librelane 2.4.0.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of librelane might be problematic. Click here for more details.

Files changed (166) hide show
  1. librelane/__init__.py +38 -0
  2. librelane/__main__.py +470 -0
  3. librelane/__version__.py +43 -0
  4. librelane/common/__init__.py +61 -0
  5. librelane/common/cli.py +75 -0
  6. librelane/common/drc.py +245 -0
  7. librelane/common/generic_dict.py +319 -0
  8. librelane/common/metrics/__init__.py +35 -0
  9. librelane/common/metrics/__main__.py +413 -0
  10. librelane/common/metrics/library.py +354 -0
  11. librelane/common/metrics/metric.py +186 -0
  12. librelane/common/metrics/util.py +279 -0
  13. librelane/common/misc.py +402 -0
  14. librelane/common/ring_buffer.py +63 -0
  15. librelane/common/tcl.py +80 -0
  16. librelane/common/toolbox.py +549 -0
  17. librelane/common/tpe.py +41 -0
  18. librelane/common/types.py +117 -0
  19. librelane/config/__init__.py +32 -0
  20. librelane/config/__main__.py +158 -0
  21. librelane/config/config.py +1025 -0
  22. librelane/config/flow.py +490 -0
  23. librelane/config/pdk_compat.py +255 -0
  24. librelane/config/preprocessor.py +464 -0
  25. librelane/config/removals.py +45 -0
  26. librelane/config/variable.py +722 -0
  27. librelane/container.py +264 -0
  28. librelane/env_info.py +306 -0
  29. librelane/examples/spm/config.yaml +33 -0
  30. librelane/examples/spm/pin_order.cfg +14 -0
  31. librelane/examples/spm/src/impl.sdc +73 -0
  32. librelane/examples/spm/src/signoff.sdc +68 -0
  33. librelane/examples/spm/src/spm.v +73 -0
  34. librelane/examples/spm/verify/spm_tb.v +106 -0
  35. librelane/examples/spm-user_project_wrapper/SPM_example.v +286 -0
  36. librelane/examples/spm-user_project_wrapper/base_sdc_file.sdc +145 -0
  37. librelane/examples/spm-user_project_wrapper/config-tut.json +12 -0
  38. librelane/examples/spm-user_project_wrapper/config.json +13 -0
  39. librelane/examples/spm-user_project_wrapper/defines.v +66 -0
  40. librelane/examples/spm-user_project_wrapper/template.def +7656 -0
  41. librelane/examples/spm-user_project_wrapper/user_project_wrapper.v +123 -0
  42. librelane/flows/__init__.py +24 -0
  43. librelane/flows/builtins.py +18 -0
  44. librelane/flows/classic.py +330 -0
  45. librelane/flows/cli.py +463 -0
  46. librelane/flows/flow.py +985 -0
  47. librelane/flows/misc.py +71 -0
  48. librelane/flows/optimizing.py +179 -0
  49. librelane/flows/sequential.py +367 -0
  50. librelane/flows/synth_explore.py +173 -0
  51. librelane/logging/__init__.py +40 -0
  52. librelane/logging/logger.py +323 -0
  53. librelane/open_pdks_rev +1 -0
  54. librelane/plugins.py +21 -0
  55. librelane/py.typed +0 -0
  56. librelane/scripts/base.sdc +80 -0
  57. librelane/scripts/klayout/Readme.md +2 -0
  58. librelane/scripts/klayout/open_design.py +63 -0
  59. librelane/scripts/klayout/render.py +121 -0
  60. librelane/scripts/klayout/stream_out.py +176 -0
  61. librelane/scripts/klayout/xml_drc_report_to_json.py +45 -0
  62. librelane/scripts/klayout/xor.drc +120 -0
  63. librelane/scripts/magic/Readme.md +1 -0
  64. librelane/scripts/magic/common/read.tcl +114 -0
  65. librelane/scripts/magic/def/antenna_check.tcl +35 -0
  66. librelane/scripts/magic/def/mag.tcl +19 -0
  67. librelane/scripts/magic/def/mag_gds.tcl +81 -0
  68. librelane/scripts/magic/drc.tcl +79 -0
  69. librelane/scripts/magic/extract_spice.tcl +98 -0
  70. librelane/scripts/magic/gds/drc_batch.tcl +74 -0
  71. librelane/scripts/magic/gds/erase_box.tcl +32 -0
  72. librelane/scripts/magic/gds/extras_mag.tcl +47 -0
  73. librelane/scripts/magic/gds/mag_with_pointers.tcl +32 -0
  74. librelane/scripts/magic/get_bbox.tcl +11 -0
  75. librelane/scripts/magic/lef/extras_maglef.tcl +63 -0
  76. librelane/scripts/magic/lef/maglef.tcl +27 -0
  77. librelane/scripts/magic/lef.tcl +57 -0
  78. librelane/scripts/magic/open.tcl +28 -0
  79. librelane/scripts/magic/wrapper.tcl +19 -0
  80. librelane/scripts/netgen/setup.tcl +28 -0
  81. librelane/scripts/odbpy/apply_def_template.py +49 -0
  82. librelane/scripts/odbpy/cell_frequency.py +107 -0
  83. librelane/scripts/odbpy/check_antenna_properties.py +116 -0
  84. librelane/scripts/odbpy/contextualize.py +109 -0
  85. librelane/scripts/odbpy/defutil.py +574 -0
  86. librelane/scripts/odbpy/diodes.py +373 -0
  87. librelane/scripts/odbpy/disconnected_pins.py +305 -0
  88. librelane/scripts/odbpy/exception_codes.py +17 -0
  89. librelane/scripts/odbpy/filter_unannotated.py +100 -0
  90. librelane/scripts/odbpy/io_place.py +482 -0
  91. librelane/scripts/odbpy/label_macro_pins.py +277 -0
  92. librelane/scripts/odbpy/lefutil.py +97 -0
  93. librelane/scripts/odbpy/placers.py +162 -0
  94. librelane/scripts/odbpy/power_utils.py +395 -0
  95. librelane/scripts/odbpy/random_place.py +57 -0
  96. librelane/scripts/odbpy/reader.py +246 -0
  97. librelane/scripts/odbpy/remove_buffers.py +173 -0
  98. librelane/scripts/odbpy/snap_to_grid.py +57 -0
  99. librelane/scripts/odbpy/wire_lengths.py +93 -0
  100. librelane/scripts/openroad/antenna_check.tcl +20 -0
  101. librelane/scripts/openroad/antenna_repair.tcl +31 -0
  102. librelane/scripts/openroad/basic_mp.tcl +24 -0
  103. librelane/scripts/openroad/buffer_list.tcl +10 -0
  104. librelane/scripts/openroad/common/dpl.tcl +24 -0
  105. librelane/scripts/openroad/common/dpl_cell_pad.tcl +26 -0
  106. librelane/scripts/openroad/common/grt.tcl +32 -0
  107. librelane/scripts/openroad/common/io.tcl +476 -0
  108. librelane/scripts/openroad/common/pdn_cfg.tcl +135 -0
  109. librelane/scripts/openroad/common/resizer.tcl +103 -0
  110. librelane/scripts/openroad/common/set_global_connections.tcl +78 -0
  111. librelane/scripts/openroad/common/set_layer_adjustments.tcl +31 -0
  112. librelane/scripts/openroad/common/set_power_nets.tcl +30 -0
  113. librelane/scripts/openroad/common/set_rc.tcl +75 -0
  114. librelane/scripts/openroad/common/set_routing_layers.tcl +30 -0
  115. librelane/scripts/openroad/cts.tcl +80 -0
  116. librelane/scripts/openroad/cut_rows.tcl +24 -0
  117. librelane/scripts/openroad/dpl.tcl +24 -0
  118. librelane/scripts/openroad/drt.tcl +37 -0
  119. librelane/scripts/openroad/fill.tcl +30 -0
  120. librelane/scripts/openroad/floorplan.tcl +145 -0
  121. librelane/scripts/openroad/gpl.tcl +88 -0
  122. librelane/scripts/openroad/grt.tcl +30 -0
  123. librelane/scripts/openroad/gui.tcl +15 -0
  124. librelane/scripts/openroad/insert_buffer.tcl +127 -0
  125. librelane/scripts/openroad/ioplacer.tcl +67 -0
  126. librelane/scripts/openroad/irdrop.tcl +51 -0
  127. librelane/scripts/openroad/pdn.tcl +52 -0
  128. librelane/scripts/openroad/rcx.tcl +32 -0
  129. librelane/scripts/openroad/repair_design.tcl +70 -0
  130. librelane/scripts/openroad/repair_design_postgrt.tcl +48 -0
  131. librelane/scripts/openroad/rsz_timing_postcts.tcl +68 -0
  132. librelane/scripts/openroad/rsz_timing_postgrt.tcl +70 -0
  133. librelane/scripts/openroad/sta/check_macro_instances.tcl +53 -0
  134. librelane/scripts/openroad/sta/corner.tcl +393 -0
  135. librelane/scripts/openroad/tapcell.tcl +25 -0
  136. librelane/scripts/openroad/write_views.tcl +27 -0
  137. librelane/scripts/pyosys/construct_abc_script.py +177 -0
  138. librelane/scripts/pyosys/json_header.py +84 -0
  139. librelane/scripts/pyosys/synthesize.py +493 -0
  140. librelane/scripts/pyosys/ys_common.py +153 -0
  141. librelane/scripts/tclsh/hello.tcl +1 -0
  142. librelane/state/__init__.py +24 -0
  143. librelane/state/__main__.py +61 -0
  144. librelane/state/design_format.py +180 -0
  145. librelane/state/state.py +351 -0
  146. librelane/steps/__init__.py +61 -0
  147. librelane/steps/__main__.py +511 -0
  148. librelane/steps/checker.py +637 -0
  149. librelane/steps/common_variables.py +340 -0
  150. librelane/steps/cvc_rv.py +169 -0
  151. librelane/steps/klayout.py +509 -0
  152. librelane/steps/magic.py +566 -0
  153. librelane/steps/misc.py +160 -0
  154. librelane/steps/netgen.py +253 -0
  155. librelane/steps/odb.py +955 -0
  156. librelane/steps/openroad.py +2433 -0
  157. librelane/steps/openroad_alerts.py +102 -0
  158. librelane/steps/pyosys.py +629 -0
  159. librelane/steps/step.py +1547 -0
  160. librelane/steps/tclstep.py +288 -0
  161. librelane/steps/verilator.py +222 -0
  162. librelane/steps/yosys.py +371 -0
  163. librelane-2.4.0.dev0.dist-info/METADATA +151 -0
  164. librelane-2.4.0.dev0.dist-info/RECORD +166 -0
  165. librelane-2.4.0.dev0.dist-info/WHEEL +4 -0
  166. librelane-2.4.0.dev0.dist-info/entry_points.txt +8 -0
librelane/steps/odb.py ADDED
@@ -0,0 +1,955 @@
1
+ # Copyright 2023 Efabless Corporation
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ import os
15
+ import re
16
+ import json
17
+ import shutil
18
+ from math import inf
19
+ from decimal import Decimal
20
+ from functools import reduce
21
+ from abc import abstractmethod
22
+ from typing import Dict, List, Literal, Optional, Tuple
23
+
24
+
25
+ from .common_variables import io_layer_variables
26
+ from .openroad_alerts import (
27
+ OpenROADAlert,
28
+ OpenROADOutputProcessor,
29
+ )
30
+ from .openroad import DetailedPlacement, GlobalRouting
31
+ from .tclstep import TclStep
32
+ from .step import (
33
+ ViewsUpdate,
34
+ MetricsUpdate,
35
+ Step,
36
+ StepException,
37
+ CompositeStep,
38
+ DefaultOutputProcessor,
39
+ )
40
+ from ..logging import info, verbose
41
+ from ..config import Variable, Macro, Instance
42
+ from ..state import State, DesignFormat
43
+ from ..common import Path, get_script_dir
44
+
45
+ inf_rx = re.compile(r"\b(-?)inf\b")
46
+
47
+
48
+ class OdbpyStep(Step):
49
+ inputs = [DesignFormat.ODB]
50
+ outputs = [DesignFormat.ODB, DesignFormat.DEF]
51
+
52
+ output_processors = [OpenROADOutputProcessor, DefaultOutputProcessor]
53
+
54
+ def on_alert(self, alert: OpenROADAlert) -> OpenROADAlert:
55
+ if alert.code in [
56
+ "ORD-0039", # .openroad ignored with -python
57
+ "ODB-0220", # LEF thing obsolete
58
+ ]:
59
+ return alert
60
+ if alert.cls == "error":
61
+ self.err(str(alert), extra={"key": alert.code})
62
+ elif alert.cls == "warning":
63
+ self.warn(str(alert), extra={"key": alert.code})
64
+ return alert
65
+
66
+ def run(self, state_in, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
67
+ kwargs, env = self.extract_env(kwargs)
68
+
69
+ automatic_outputs = set(self.outputs).intersection(
70
+ [DesignFormat.ODB, DesignFormat.DEF]
71
+ )
72
+
73
+ views_updates: ViewsUpdate = {}
74
+ command = self.get_command()
75
+ for output in automatic_outputs:
76
+ filename = f"{self.config['DESIGN_NAME']}.{output.value.extension}"
77
+ file_path = os.path.join(self.step_dir, filename)
78
+ command.append(f"--output-{output.value.id}")
79
+ command.append(file_path)
80
+ views_updates[output] = Path(file_path)
81
+
82
+ command += [
83
+ str(state_in[DesignFormat.ODB]),
84
+ ]
85
+
86
+ env["PYTHONPATH"] = (
87
+ f'{os.path.join(get_script_dir(), "odbpy")}:{env.get("PYTHONPATH")}'
88
+ )
89
+
90
+ subprocess_result = self.run_subprocess(
91
+ command,
92
+ env=env,
93
+ **kwargs,
94
+ )
95
+
96
+ metrics_path = os.path.join(self.step_dir, "or_metrics_out.json")
97
+ metrics_updates: MetricsUpdate = subprocess_result["generated_metrics"]
98
+ if os.path.exists(metrics_path):
99
+ or_metrics_out = json.loads(open(metrics_path).read(), parse_float=Decimal)
100
+ for key, value in or_metrics_out.items():
101
+ if value == "Infinity":
102
+ or_metrics_out[key] = inf
103
+ elif value == "-Infinity":
104
+ or_metrics_out[key] = -inf
105
+ metrics_updates.update(or_metrics_out)
106
+
107
+ return views_updates, metrics_updates
108
+
109
+ def get_command(self) -> List[str]:
110
+ metrics_path = os.path.join(self.step_dir, "or_metrics_out.json")
111
+
112
+ tech_lefs = self.toolbox.filter_views(self.config, self.config["TECH_LEFS"])
113
+ if len(tech_lefs) != 1:
114
+ raise StepException(
115
+ "Misconfigured SCL: 'TECH_LEFS' must return exactly one Tech LEF for its default timing corner."
116
+ )
117
+
118
+ lefs = ["--input-lef", str(tech_lefs[0])]
119
+ for lef in self.config["CELL_LEFS"]:
120
+ lefs.append("--input-lef")
121
+ lefs.append(lef)
122
+ if extra_lefs := self.config["EXTRA_LEFS"]:
123
+ for lef in extra_lefs:
124
+ lefs.append("--input-lef")
125
+ lefs.append(lef)
126
+ if (design_lef := self.state_in.result()[DesignFormat.LEF]) and (
127
+ DesignFormat.LEF in self.inputs
128
+ ):
129
+ lefs.append("--design-lef")
130
+ lefs.append(str(design_lef))
131
+ return (
132
+ [
133
+ "openroad",
134
+ "-exit",
135
+ "-no_splash",
136
+ "-metrics",
137
+ str(metrics_path),
138
+ "-python",
139
+ self.get_script_path(),
140
+ ]
141
+ + self.get_subcommand()
142
+ + lefs
143
+ )
144
+
145
+ @abstractmethod
146
+ def get_script_path(self) -> str:
147
+ pass
148
+
149
+ def get_subcommand(self) -> List[str]:
150
+ return []
151
+
152
+
153
+ @Step.factory.register()
154
+ class CheckMacroAntennaProperties(OdbpyStep):
155
+ id = "Odb.CheckMacroAntennaProperties"
156
+ name = "Check Antenna Properties of Macros Pins in Their LEF Views"
157
+ inputs = OdbpyStep.inputs
158
+ outputs = []
159
+
160
+ def get_script_path(self):
161
+ return os.path.join(
162
+ get_script_dir(),
163
+ "odbpy",
164
+ "check_antenna_properties.py",
165
+ )
166
+
167
+ def get_cells(self) -> List[str]:
168
+ macros = self.config["MACROS"]
169
+ cells = []
170
+ if macros:
171
+ cells = list(macros.keys())
172
+ return cells
173
+
174
+ def get_report_path(self) -> str:
175
+ return os.path.join(self.step_dir, "report.yaml")
176
+
177
+ def get_command(self) -> List[str]:
178
+ args = ["--report-file", self.get_report_path()]
179
+ for name in self.get_cells():
180
+ args += ["--cell-name", name]
181
+ return super().get_command() + args
182
+
183
+ def run(self, state_in, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
184
+ if not self.get_cells():
185
+ info("No cells provided, skipping…")
186
+ return {}, {}
187
+ return super().run(state_in, **kwargs)
188
+
189
+
190
+ @Step.factory.register()
191
+ class CheckDesignAntennaProperties(CheckMacroAntennaProperties):
192
+ id = "Odb.CheckDesignAntennaProperties"
193
+ name = "Check Antenna Properties of Pins in The Generated Design LEF view"
194
+ inputs = CheckMacroAntennaProperties.inputs + [DesignFormat.LEF]
195
+
196
+ def get_cells(self) -> List[str]:
197
+ return [self.config["DESIGN_NAME"]]
198
+
199
+
200
+ @Step.factory.register()
201
+ class ApplyDEFTemplate(OdbpyStep):
202
+ """
203
+ Copies the floorplan of a "template" DEF file for a new design, i.e.,
204
+ it will copy the die area, core area, and non-power pin names and locations.
205
+ """
206
+
207
+ id = "Odb.ApplyDEFTemplate"
208
+ name = "Apply DEF Template"
209
+
210
+ config_vars = [
211
+ Variable(
212
+ "FP_DEF_TEMPLATE",
213
+ Optional[Path],
214
+ "Points to the DEF file to be used as a template.",
215
+ ),
216
+ Variable(
217
+ "FP_TEMPLATE_MATCH_MODE",
218
+ Literal["strict", "permissive"],
219
+ "Whether to require that the pin set of the DEF template and the design should be identical. In permissive mode, pins that are in the design and not in the template will be excluded, and vice versa.",
220
+ default="strict",
221
+ ),
222
+ Variable(
223
+ "FP_TEMPLATE_COPY_POWER_PINS",
224
+ bool,
225
+ "Whether to *always* copy all power pins from the DEF template to the design.",
226
+ default=False,
227
+ ),
228
+ ]
229
+
230
+ def get_script_path(self):
231
+ return os.path.join(
232
+ get_script_dir(),
233
+ "odbpy",
234
+ "apply_def_template.py",
235
+ )
236
+
237
+ def get_command(self) -> List[str]:
238
+ args = [
239
+ "--def-template",
240
+ self.config["FP_DEF_TEMPLATE"],
241
+ f"--{self.config['FP_TEMPLATE_MATCH_MODE']}",
242
+ ]
243
+ if self.config["FP_TEMPLATE_COPY_POWER_PINS"]:
244
+ args.append("--copy-def-power")
245
+ return super().get_command() + args
246
+
247
+ def run(self, state_in, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
248
+ if self.config["FP_DEF_TEMPLATE"] is None:
249
+ info("No DEF template provided, skipping…")
250
+ return {}, {}
251
+
252
+ views_updates, metrics_updates = super().run(state_in, **kwargs)
253
+ design_area_string = self.state_in.result().metrics.get("design__die__bbox")
254
+ if design_area_string:
255
+ template_area_string = metrics_updates["design__die__bbox"]
256
+ template_area = [Decimal(point) for point in template_area_string.split()]
257
+ design_area = [Decimal(point) for point in design_area_string.split()]
258
+ if template_area != design_area:
259
+ self.warn(
260
+ "The die area specificied in FP_DEF_TEMPLATE is different than the design die area. Pin placement may be incorrect."
261
+ )
262
+ self.warn(
263
+ f"Design area: {design_area_string}. Template def area: {template_area_string}"
264
+ )
265
+ return views_updates, {}
266
+
267
+
268
+ @Step.factory.register()
269
+ class SetPowerConnections(OdbpyStep):
270
+ """
271
+ Uses JSON netlist and module information in Odb to add global power
272
+ connections for macros at the top level of a design.
273
+
274
+ If the JSON netlist is hierarchical (e.g. by using a keep hierarchy
275
+ attribute) this Step emits a warning and does not attempt to connect any
276
+ macros instantiated within submodules.
277
+ """
278
+
279
+ id = "Odb.SetPowerConnections"
280
+ name = "Set Power Connections"
281
+ inputs = [DesignFormat.JSON_HEADER, DesignFormat.ODB]
282
+
283
+ def get_script_path(self):
284
+ return os.path.join(get_script_dir(), "odbpy", "power_utils.py")
285
+
286
+ def get_subcommand(self) -> List[str]:
287
+ return ["set-power-connections"]
288
+
289
+ def get_command(self) -> List[str]:
290
+ state_in = self.state_in.result()
291
+ return super().get_command() + [
292
+ "--input-json",
293
+ str(state_in[DesignFormat.JSON_HEADER]),
294
+ ]
295
+
296
+
297
+ @Step.factory.register()
298
+ class WriteVerilogHeader(OdbpyStep):
299
+ """
300
+ Writes a Verilog header of the module using information from the generated
301
+ PDN, guarded by the value of ``VERILOG_POWER_DEFINE``, and the JSON header.
302
+ """
303
+
304
+ id = "Odb.WriteVerilogHeader"
305
+ name = "Write Verilog Header"
306
+ inputs = [DesignFormat.ODB, DesignFormat.JSON_HEADER]
307
+ outputs = [DesignFormat.VERILOG_HEADER]
308
+
309
+ config_vars = OdbpyStep.config_vars + [
310
+ Variable(
311
+ "VERILOG_POWER_DEFINE",
312
+ Optional[str],
313
+ "Specifies the name of the define used to guard power and ground connections in the output Verilog header.",
314
+ deprecated_names=["SYNTH_USE_PG_PINS_DEFINES", "SYNTH_POWER_DEFINE"],
315
+ default="USE_POWER_PINS",
316
+ ),
317
+ ]
318
+
319
+ def get_script_path(self):
320
+ return os.path.join(get_script_dir(), "odbpy", "power_utils.py")
321
+
322
+ def get_subcommand(self) -> List[str]:
323
+ return ["write-verilog-header"]
324
+
325
+ def get_command(self) -> List[str]:
326
+ state_in = self.state_in.result()
327
+ command = super().get_command() + [
328
+ "--output-vh",
329
+ os.path.join(self.step_dir, f"{self.config['DESIGN_NAME']}.vh"),
330
+ "--input-json",
331
+ str(state_in[DesignFormat.JSON_HEADER]),
332
+ ]
333
+ if self.config.get("VERILOG_POWER_DEFINE") is not None:
334
+ command += ["--power-define", self.config["VERILOG_POWER_DEFINE"]]
335
+ else:
336
+ self.warn(
337
+ "VERILOG_POWER_DEFINE undefined. Verilog Header will not include power ports."
338
+ )
339
+
340
+ return command
341
+
342
+ def run(self, state_in, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
343
+ views_updates, metrics_updates = super().run(state_in, **kwargs)
344
+ views_updates[DesignFormat.VERILOG_HEADER] = Path(
345
+ os.path.join(self.step_dir, f"{self.config['DESIGN_NAME']}.vh")
346
+ )
347
+ return views_updates, metrics_updates
348
+
349
+
350
+ @Step.factory.register()
351
+ class ManualMacroPlacement(OdbpyStep):
352
+ """
353
+ Performs macro placement using a simple configuration file. The file is
354
+ defined as a line-break delimited list of instances and positions, in the
355
+ format ``instance_name X_pos Y_pos Orientation``.
356
+
357
+ If no macro instances are configured, this step is skipped.
358
+ """
359
+
360
+ id = "Odb.ManualMacroPlacement"
361
+ name = "Manual Macro Placement"
362
+
363
+ config_vars = [
364
+ Variable(
365
+ "MACRO_PLACEMENT_CFG",
366
+ Optional[Path],
367
+ "Path to an optional override for instance placement instead of the `MACROS` object for compatibility with LibreLane 1. If both are `None`, this step is skipped.",
368
+ ),
369
+ ]
370
+
371
+ def get_script_path(self):
372
+ return os.path.join(get_script_dir(), "odbpy", "placers.py")
373
+
374
+ def get_subcommand(self) -> List[str]:
375
+ return ["manual-macro-placement"]
376
+
377
+ def get_command(self) -> List[str]:
378
+ return super().get_command() + [
379
+ "--config",
380
+ os.path.join(self.step_dir, "placement.cfg"),
381
+ "--fixed",
382
+ ]
383
+
384
+ def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
385
+ cfg_file = Path(os.path.join(self.step_dir, "placement.cfg"))
386
+ if cfg_ref := self.config.get("MACRO_PLACEMENT_CFG"):
387
+ self.warn(
388
+ "Using 'MACRO_PLACEMENT_CFG' is deprecated. It is recommended to use the new 'MACROS' configuration variable."
389
+ )
390
+ shutil.copyfile(cfg_ref, cfg_file)
391
+ elif macros := self.config.get("MACROS"):
392
+ instance_count = reduce(
393
+ lambda x, y: x + len(y.instances), macros.values(), 0
394
+ )
395
+ if instance_count >= 1:
396
+ with open(cfg_file, "w") as f:
397
+ for module, macro in macros.items():
398
+ if not isinstance(macro, Macro):
399
+ raise StepException(
400
+ f"Misconstructed configuration: macro definition for key {module} is not of type 'Macro'."
401
+ )
402
+ for name, data in macro.instances.items():
403
+ if data.location is not None:
404
+ if data.orientation is None:
405
+ raise StepException(
406
+ f"Instance {name} of macro {module} has a location configured, but no orientation."
407
+ )
408
+ f.write(
409
+ f"{name} {data.location[0]} {data.location[1]} {data.orientation}\n"
410
+ )
411
+ else:
412
+ verbose(
413
+ f"Instance {name} of macro {module} has no location configured, ignoring…"
414
+ )
415
+
416
+ if not cfg_file.exists():
417
+ info(f"No instances found, skipping '{self.id}'…")
418
+ return {}, {}
419
+
420
+ return super().run(state_in, **kwargs)
421
+
422
+
423
+ @Step.factory.register()
424
+ class ReportWireLength(OdbpyStep):
425
+ """
426
+ Outputs a CSV of long wires, printed by length. Useful as a design aid to
427
+ detect when one wire is connected to too many things.
428
+ """
429
+
430
+ outputs = []
431
+
432
+ id = "Odb.ReportWireLength"
433
+ name = "Report Wire Length"
434
+ outputs = []
435
+
436
+ def get_script_path(self):
437
+ return os.path.join(get_script_dir(), "odbpy", "wire_lengths.py")
438
+
439
+ def get_command(self) -> List[str]:
440
+ return super().get_command() + [
441
+ "--human-readable",
442
+ "--report-out",
443
+ os.path.join(self.step_dir, "wire_lengths.csv"),
444
+ ]
445
+
446
+
447
+ @Step.factory.register()
448
+ class ReportDisconnectedPins(OdbpyStep):
449
+ """
450
+ Creates a table of disconnected pins in the design, updating metrics as
451
+ appropriate.
452
+
453
+ Disconnected pins may be marked "critical" if they are very likely to
454
+ result in a dead design. We determine if a pin is critical as follows:
455
+
456
+ * For the top-level macro: for these four kinds of pins: inputs, outputs,
457
+ power inouts, and ground inouts, at least one of each kind must be
458
+ connected or else all pins of a certain kind are counted as critical
459
+ disconnected pins.
460
+ * For instances:
461
+ * Any unconnected input is a critical disconnected pin.
462
+ * If there isn't at least one output connected, all disconnected
463
+ outputs are critical disconnected pins.
464
+ * Any disconnected power inout pins are critical disconnected pins.
465
+
466
+ The metrics ``design__disconnected_pin__count`` and
467
+ ``design__critical_disconnected_pin__count`` is updated. It is recommended
468
+ to use the checker ``Checker.DisconnectedPins`` to check that there are
469
+ no critical disconnected pins.
470
+ """
471
+
472
+ id = "Odb.ReportDisconnectedPins"
473
+ name = "Report Disconnected Pins"
474
+
475
+ config_vars = OdbpyStep.config_vars + [
476
+ Variable(
477
+ "IGNORE_DISCONNECTED_MODULES",
478
+ Optional[List[str]],
479
+ "Modules (or cells) to ignore when checking for disconnected pins.",
480
+ pdk=True,
481
+ ),
482
+ ]
483
+
484
+ def get_script_path(self):
485
+ return os.path.join(get_script_dir(), "odbpy", "disconnected_pins.py")
486
+
487
+ def get_command(self) -> List[str]:
488
+ command = super().get_command()
489
+ if ignored_modules := self.config["IGNORE_DISCONNECTED_MODULES"]:
490
+ for module in ignored_modules:
491
+ command.append("--ignore-module")
492
+ command.append(module)
493
+ command.append("--write-full-table-to")
494
+ command.append(os.path.join(self.step_dir, "full_disconnected_pins_table.txt"))
495
+ return command
496
+
497
+
498
+ @Step.factory.register()
499
+ class AddRoutingObstructions(OdbpyStep):
500
+ id = "Odb.AddRoutingObstructions"
501
+ name = "Add Obstructions"
502
+ config_vars = [
503
+ Variable(
504
+ "ROUTING_OBSTRUCTIONS",
505
+ Optional[List[str]],
506
+ "Add routing obstructions to the design. If set to `None`, this step is skipped."
507
+ + " Format of each obstruction item is: layer llx lly urx ury.",
508
+ units="µm",
509
+ default=None,
510
+ deprecated_names=["GRT_OBS"],
511
+ ),
512
+ ]
513
+
514
+ def get_obstruction_variable(self):
515
+ return self.config_vars[0]
516
+
517
+ def get_script_path(self):
518
+ return os.path.join(get_script_dir(), "odbpy", "defutil.py")
519
+
520
+ def get_subcommand(self) -> List[str]:
521
+ return ["add_obstructions"]
522
+
523
+ def get_command(self) -> List[str]:
524
+ command = super().get_command()
525
+ if obstructions := self.config[self.config_vars[0].name]:
526
+ for obstruction in obstructions:
527
+ command.append("--obstructions")
528
+ command.append(obstruction)
529
+ return command
530
+
531
+ def run(self, state_in, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
532
+ if self.config[self.get_obstruction_variable().name] is None:
533
+ info(
534
+ f"'{self.get_obstruction_variable().name}' is not defined. Skipping '{self.id}'…"
535
+ )
536
+ return {}, {}
537
+ return super().run(state_in, **kwargs)
538
+
539
+
540
+ @Step.factory.register()
541
+ class RemoveRoutingObstructions(AddRoutingObstructions):
542
+ id = "Odb.RemoveRoutingObstructions"
543
+ name = "Remove Obstructions"
544
+
545
+ def get_subcommand(self) -> List[str]:
546
+ return ["remove_obstructions"]
547
+
548
+
549
+ @Step.factory.register()
550
+ class AddPDNObstructions(AddRoutingObstructions):
551
+ id = "Odb.AddPDNObstructions"
552
+ name = "Add PDN obstructions"
553
+
554
+ config_vars = [
555
+ Variable(
556
+ "PDN_OBSTRUCTIONS",
557
+ Optional[List[str]],
558
+ "Add routing obstructions to the design before PDN stage. If set to `None`, this step is skipped."
559
+ + " Format of each obstruction item is: layer llx lly urx ury.",
560
+ units="µm",
561
+ default=None,
562
+ ),
563
+ ]
564
+
565
+
566
+ @Step.factory.register()
567
+ class RemovePDNObstructions(RemoveRoutingObstructions):
568
+ id = "Odb.RemovePDNObstructions"
569
+ name = "Remove PDN obstructions"
570
+
571
+ config_vars = AddPDNObstructions.config_vars
572
+
573
+
574
+ _migrate_unmatched_io = lambda x: "unmatched_design" if x else "none"
575
+
576
+
577
+ @Step.factory.register()
578
+ class CustomIOPlacement(OdbpyStep):
579
+ """
580
+ Places I/O pins using a custom script, which uses a "pin order configuration"
581
+ file.
582
+
583
+ Check the reference documentation for the structure of said file.
584
+ """
585
+
586
+ id = "Odb.CustomIOPlacement"
587
+ name = "Custom I/O Placement"
588
+ long_name = "Custom I/O Pin Placement Script"
589
+
590
+ config_vars = io_layer_variables + [
591
+ Variable(
592
+ "FP_IO_VLENGTH",
593
+ Optional[Decimal],
594
+ """
595
+ The length of the pins with a north or south orientation. If unspecified by a PDK, the script will use whichever is higher of the following two values:
596
+ * The pin width
597
+ * The minimum value satisfying the minimum area constraint given the pin width
598
+ """,
599
+ units="µm",
600
+ pdk=True,
601
+ ),
602
+ Variable(
603
+ "FP_IO_HLENGTH",
604
+ Optional[Decimal],
605
+ """
606
+ The length of the pins with an east or west orientation. If unspecified by a PDK, the script will use whichever is higher of the following two values:
607
+ * The pin width
608
+ * The minimum value satisfying the minimum area constraint given the pin width
609
+ """,
610
+ units="µm",
611
+ pdk=True,
612
+ ),
613
+ Variable(
614
+ "FP_PIN_ORDER_CFG",
615
+ Optional[Path],
616
+ "Path to the configuration file. If set to `None`, this step is skipped.",
617
+ ),
618
+ Variable(
619
+ "ERRORS_ON_UNMATCHED_IO",
620
+ Literal["none", "unmatched_design", "unmatched_cfg", "both"],
621
+ "Controls whether to emit an error in: no situation, when pins exist in the design that do not exist in the config file, when pins exist in the config file that do not exist in the design, and both respectively. `both` is recommended, as the default is only for backwards compatibility with LibreLane 1.",
622
+ default="unmatched_design", # Backwards compatible with LibreLane 1
623
+ deprecated_names=[
624
+ ("QUIT_ON_UNMATCHED_IO", _migrate_unmatched_io),
625
+ ],
626
+ ),
627
+ ]
628
+
629
+ def get_script_path(self):
630
+ return os.path.join(get_script_dir(), "odbpy", "io_place.py")
631
+
632
+ def get_command(self) -> List[str]:
633
+ length_args = []
634
+ if self.config["FP_IO_VLENGTH"] is not None:
635
+ length_args += ["--ver-length", self.config["FP_IO_VLENGTH"]]
636
+ if self.config["FP_IO_HLENGTH"] is not None:
637
+ length_args += ["--hor-length", self.config["FP_IO_HLENGTH"]]
638
+
639
+ return (
640
+ super().get_command()
641
+ + [
642
+ "--config",
643
+ self.config["FP_PIN_ORDER_CFG"],
644
+ "--hor-layer",
645
+ self.config["FP_IO_HLAYER"],
646
+ "--ver-layer",
647
+ self.config["FP_IO_VLAYER"],
648
+ "--hor-width-mult",
649
+ str(self.config["FP_IO_VTHICKNESS_MULT"]),
650
+ "--ver-width-mult",
651
+ str(self.config["FP_IO_HTHICKNESS_MULT"]),
652
+ "--hor-extension",
653
+ str(self.config["FP_IO_HEXTEND"]),
654
+ "--ver-extension",
655
+ str(self.config["FP_IO_VEXTEND"]),
656
+ "--unmatched-error",
657
+ self.config["ERRORS_ON_UNMATCHED_IO"],
658
+ ]
659
+ + length_args
660
+ )
661
+
662
+ def run(self, state_in, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
663
+ if self.config["FP_PIN_ORDER_CFG"] is None:
664
+ info("No custom floorplan file configured, skipping…")
665
+ return {}, {}
666
+ return super().run(state_in, **kwargs)
667
+
668
+
669
+ @Step.factory.register()
670
+ class PortDiodePlacement(OdbpyStep):
671
+ """
672
+ Unconditionally inserts diodes on design ports diodes on ports,
673
+ to mitigate the `antenna effect <https://en.wikipedia.org/wiki/Antenna_effect>`_.
674
+
675
+ Useful for hardening macros, where ports may get long wires that are
676
+ unaccounted for when hardening a top-level chip.
677
+
678
+ The placement is **not legalized**.
679
+ """
680
+
681
+ id = "Odb.PortDiodePlacement"
682
+ name = "Port Diode Placement Script"
683
+
684
+ config_vars = [
685
+ Variable(
686
+ "DIODE_ON_PORTS",
687
+ Literal["none", "in", "out", "both"],
688
+ "Always insert diodes on ports with the specified polarities.",
689
+ default="none",
690
+ ),
691
+ Variable(
692
+ "GPL_CELL_PADDING",
693
+ Decimal,
694
+ "Cell padding value (in sites) for global placement. Used by this step only to emit a warning if it's 0.",
695
+ units="sites",
696
+ pdk=True,
697
+ ),
698
+ ]
699
+
700
+ def get_script_path(self):
701
+ return os.path.join(get_script_dir(), "odbpy", "diodes.py")
702
+
703
+ def get_subcommand(self) -> List[str]:
704
+ return ["place"]
705
+
706
+ def get_command(self) -> List[str]:
707
+ cell, pin = self.config["DIODE_CELL"].split("/")
708
+
709
+ return super().get_command() + [
710
+ "--diode-cell",
711
+ cell,
712
+ "--diode-pin",
713
+ pin,
714
+ "--port-protect",
715
+ self.config["DIODE_ON_PORTS"],
716
+ "--threshold",
717
+ "Infinity",
718
+ ]
719
+
720
+ def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
721
+ if self.config["DIODE_ON_PORTS"] == "none":
722
+ info("'DIODE_ON_PORTS' is set to 'none': skipping…")
723
+ return {}, {}
724
+
725
+ if self.config["GPL_CELL_PADDING"] == 0:
726
+ self.warn(
727
+ "'GPL_CELL_PADDING' is set to 0. This step may cause overlap failures."
728
+ )
729
+
730
+ return super().run(state_in, **kwargs)
731
+
732
+
733
+ @Step.factory.register()
734
+ class DiodesOnPorts(CompositeStep):
735
+ """
736
+ Unconditionally inserts diodes on design ports diodes on ports,
737
+ to mitigate the `antenna effect <https://en.wikipedia.org/wiki/Antenna_effect>`_.
738
+
739
+ Useful for hardening macros, where ports may get long wires that are
740
+ unaccounted for when hardening a top-level chip.
741
+
742
+ The placement is legalized by performing detailed placement and global
743
+ routing after inserting the diodes.
744
+
745
+ Prior to beta 16, this step did not legalize its placement: if you would
746
+ like to retain the old behavior without legalization, try
747
+ ``Odb.PortDiodePlacement``.
748
+ """
749
+
750
+ id = "Odb.DiodesOnPorts"
751
+ name = "Diodes on Ports"
752
+ long_name = "Diodes on Ports Protection Routine"
753
+
754
+ Steps = [
755
+ PortDiodePlacement,
756
+ DetailedPlacement,
757
+ GlobalRouting,
758
+ ]
759
+
760
+ def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
761
+ if self.config["DIODE_ON_PORTS"] == "none":
762
+ info("'DIODE_ON_PORTS' is set to 'none': skipping…")
763
+ return {}, {}
764
+ return super().run(state_in, **kwargs)
765
+
766
+
767
+ @Step.factory.register()
768
+ class FuzzyDiodePlacement(OdbpyStep):
769
+ """
770
+ Runs a custom diode placement script to mitigate the `antenna effect <https://en.wikipedia.org/wiki/Antenna_effect>`_.
771
+
772
+ This script uses the `Manhattan length <https://en.wikipedia.org/wiki/Manhattan_distance>`_
773
+ of a (non-existent) wire at the global placement stage, and places diodes
774
+ if they exceed a certain threshold. This, however, requires some padding:
775
+ `GPL_CELL_PADDING` and `DPL_CELL_PADDING` must be higher than 0 for this
776
+ script to work reliably.
777
+
778
+ The placement is *not* legalized.
779
+
780
+ The original script was written by `Sylvain "tnt" Munaut <https://github.com/smunaut>`_.
781
+ """
782
+
783
+ id = "Odb.FuzzyDiodePlacement"
784
+ name = "Fuzzy Diode Placement"
785
+
786
+ config_vars = [
787
+ Variable(
788
+ "HEURISTIC_ANTENNA_THRESHOLD",
789
+ Decimal,
790
+ "A Manhattan distance above which a diode is recommended to be inserted by the heuristic inserter. If not specified, the heuristic algorithm.",
791
+ units="µm",
792
+ pdk=True,
793
+ ),
794
+ Variable(
795
+ "GPL_CELL_PADDING",
796
+ Decimal,
797
+ "Cell padding value (in sites) for global placement. Used by this step only to emit a warning if it's 0.",
798
+ units="sites",
799
+ pdk=True,
800
+ ),
801
+ ]
802
+
803
+ def get_script_path(self):
804
+ return os.path.join(get_script_dir(), "odbpy", "diodes.py")
805
+
806
+ def get_subcommand(self) -> List[str]:
807
+ return ["place"]
808
+
809
+ def get_command(self) -> List[str]:
810
+ cell, pin = self.config["DIODE_CELL"].split("/")
811
+
812
+ threshold_opts = []
813
+ if threshold := self.config["HEURISTIC_ANTENNA_THRESHOLD"]:
814
+ threshold_opts = ["--threshold", threshold]
815
+
816
+ return (
817
+ super().get_command()
818
+ + [
819
+ "--diode-cell",
820
+ cell,
821
+ "--diode-pin",
822
+ pin,
823
+ ]
824
+ + threshold_opts
825
+ )
826
+
827
+ def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
828
+ if self.config["GPL_CELL_PADDING"] == 0:
829
+ self.warn(
830
+ "'GPL_CELL_PADDING' is set to 0. This step may cause overlap failures."
831
+ )
832
+
833
+ return super().run(state_in, **kwargs)
834
+
835
+
836
+ @Step.factory.register()
837
+ class HeuristicDiodeInsertion(CompositeStep):
838
+ """
839
+ Runs a custom diode insertion routine to mitigate the `antenna effect <https://en.wikipedia.org/wiki/Antenna_effect>`_.
840
+
841
+ This script uses the `Manhattan length <https://en.wikipedia.org/wiki/Manhattan_distance>`_
842
+ of a (non-existent) wire at the global placement stage, and places diodes
843
+ if they exceed a certain threshold. This, however, requires some padding:
844
+ `GPL_CELL_PADDING` and `DPL_CELL_PADDING` must be higher than 0 for this
845
+ script to work reliably.
846
+
847
+ The placement is then legalized by performing detailed placement and global
848
+ routing after inserting the diodes.
849
+
850
+ The original script was written by `Sylvain "tnt" Munaut <https://github.com/smunaut>`_.
851
+
852
+ Prior to beta 16, this step did not legalize its placement: if you would
853
+ like to retain the old behavior without legalization, try
854
+ ``Odb.FuzzyDiodePlacement``.
855
+ """
856
+
857
+ id = "Odb.HeuristicDiodeInsertion"
858
+ name = "Heuristic Diode Insertion"
859
+ long_name = "Heuristic Diode Insertion Routine"
860
+
861
+ Steps = [
862
+ FuzzyDiodePlacement,
863
+ DetailedPlacement,
864
+ GlobalRouting,
865
+ ]
866
+
867
+
868
+ @Step.factory.register()
869
+ class CellFrequencyTables(OdbpyStep):
870
+ """
871
+ Creates a number of tables to show the cell frequencies by:
872
+
873
+ - Cells
874
+ - Buffer cells only
875
+ - Cell Function*
876
+ - Standard Cell Library*
877
+
878
+ * These tables only return meaningful info with PDKs distributed in the
879
+ Open_PDKs format, i.e., all cells are named ``{scl}__{cell_fn}_{size}``.
880
+ """
881
+
882
+ id = "Odb.CellFrequencyTables"
883
+ name = "Generate Cell Frequency Tables"
884
+
885
+ def get_script_path(self):
886
+ return os.path.join(
887
+ get_script_dir(),
888
+ "odbpy",
889
+ "cell_frequency.py",
890
+ )
891
+
892
+ def get_buffer_list_file(self):
893
+ return os.path.join(self.step_dir, "buffer_list.txt")
894
+
895
+ def get_buffer_list_script(self):
896
+ return os.path.join(get_script_dir(), "openroad", "buffer_list.tcl")
897
+
898
+ def run(self, state_in, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
899
+ kwargs, env = self.extract_env(kwargs)
900
+
901
+ env_copy = env.copy()
902
+ lib_list = self.toolbox.filter_views(self.config, self.config["LIB"])
903
+ env_copy["_PNR_LIBS"] = TclStep.value_to_tcl(lib_list)
904
+ super().run_subprocess(
905
+ ["openroad", "-no_splash", "-exit", self.get_buffer_list_script()],
906
+ env=env_copy,
907
+ log_to=self.get_buffer_list_file(),
908
+ )
909
+ return super().run(state_in, env=env, **kwargs)
910
+
911
+ def get_command(self) -> List[str]:
912
+ command = super().get_command()
913
+ command.append("--buffer-list")
914
+ command.append(self.get_buffer_list_file())
915
+ command.append("--out-dir")
916
+ command.append(self.step_dir)
917
+ return command
918
+
919
+
920
+ @Step.factory.register()
921
+ class ManualGlobalPlacement(OdbpyStep):
922
+ """
923
+ This is an step to override the placement of one or more instances at
924
+ user-specified locations.
925
+
926
+ Alternatively, if this is a custom design with a few cells, this can be used
927
+ in place of the global placement entirely.
928
+ """
929
+
930
+ id = "Odb.ManualGlobalPlacement"
931
+ name = "Manual Global Placement"
932
+
933
+ config_vars = OdbpyStep.config_vars + [
934
+ Variable(
935
+ "MANUAL_GLOBAL_PLACEMENTS",
936
+ Optional[Dict[str, Instance]],
937
+ description="A dictionary of instances to their global (non-legalized and unfixed) placement location.",
938
+ )
939
+ ]
940
+
941
+ def get_script_path(self) -> str:
942
+ return os.path.join(get_script_dir(), "odbpy", "placers.py")
943
+
944
+ def get_subcommand(self) -> List[str]:
945
+ return ["manual-global-placement"]
946
+
947
+ def get_command(self) -> List[str]:
948
+ assert self.config_path is not None, "get_command called before start()"
949
+ return super().get_command() + ["--step-config", self.config_path]
950
+
951
+ def run(self, state_in, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
952
+ if self.config["MANUAL_GLOBAL_PLACEMENTS"] is None:
953
+ info("'MANUAL_GLOBAL_PLACEMENTS' not set, skipping…")
954
+ return {}, {}
955
+ return super().run(state_in, **kwargs)