File size: 5,648 Bytes
34292e0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | #!/usr/bin/env python3
"""Floorplan makes the global connections right after the netlist is loaded.
global_connect skips a dont_touch instance, so floorplan.tcl makes the
global connections (GLOBAL_CONNECT_TCL) right after it loads the
netlist, before any step, the PRE_FLOORPLAN_TCL hook included, can mark
an instance dont_touch. Every instance's supply pins are then on a net,
and the rules stay in the database: a later step that creates instances
connects them with global_connect before marking them.
floorplan.tcl runs as is on a two-inverter nangate45 design, with a
PRE_FLOORPLAN_TCL hook that marks one of them dont_touch; load.tcl is
replaced by one that reads the netlist and stubs the reports.
Skipped when no openroad is available: OPENROAD_EXE or openroad on PATH.
"""
import os
import shutil
import subprocess
import tempfile
import unittest
FLOW = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
SCRIPTS = os.path.join(FLOW, "scripts")
PLATFORM = os.path.join(FLOW, "platforms", "nangate45")
LEF = os.path.join(PLATFORM, "lef")
TECH_LEF = os.path.join(LEF, "NangateOpenCellLibrary.tech.lef")
SC_LEF = os.path.join(LEF, "NangateOpenCellLibrary.macro.mod.lef")
LIB = os.path.join(PLATFORM, "lib", "NangateOpenCellLibrary_typical.lib")
DESIGN = """\
module top (input a, output y0, output y1);
INV_X1 kept (.A(a), .ZN(y0));
INV_X1 free (.A(a), .ZN(y1));
endmodule
"""
# In place of load.tcl: the netlist and liberty without an SDC, and no
# timing reports.
LOAD = f"""\
source {{{os.path.join(SCRIPTS, "util.tcl")}}}
proc load_design {{ design_file sdc_file }} {{
read_liberty {{{LIB}}}
read_lef {{{TECH_LEF}}}
read_lef {{{SC_LEF}}}
read_verilog top.v
link_design top
}}
proc report_metrics {{ args }} {{ }}
proc report_units_metric {{ }} {{ }}
proc report_layer_rc {{ }} {{ }}
proc write_endpoint_slack {{ args }} {{ }}
"""
ENV = {
"KEEP_VARS": "1",
"GLOBAL_CONNECT_TCL": os.path.join(PLATFORM, "global_connect.tcl"),
"DIE_AREA": "0 0 100 100",
"CORE_AREA": "10 10 90 90",
"PLACE_SITE": "FreePDK45_38x28_10R_NP_162NW_34O",
"MIN_ROUTING_LAYER": "metal2",
"MAX_ROUTING_LAYER": "metal10",
"ROUTING_LAYER_ADJUSTMENT": "0.5",
"DONT_USE_CELLS": "",
"SKIP_REPAIR_TIE_FANOUT": "1",
"SKIP_FLOORPLAN_REPAIR_TIMING": "1",
"WRITE_ODB_AND_SDC_EACH_STAGE": "1",
"OPENROAD_HIERARCHICAL": "0",
}
# The PRE_FLOORPLAN_TCL hook: the first step after the netlist is loaded
# that could mark an instance dont_touch.
PRE_FLOORPLAN = """\
[[ord::get_db_block] findInst kept] setDoNotTouch 1
"""
# A later step: reads floorplan's result, creates an instance and
# connects it before marking it dont_touch.
LATER = f"""\
read_lef {{{TECH_LEF}}}
read_lef {{{SC_LEF}}}
read_db 2_1_floorplan.odb
set block [ord::get_db_block]
proc supply {{ name pin }} {{
set net [[[[ord::get_db_block] findInst $name] findITerm $pin] getNet]
if {{ $net eq "NULL" }} {{
return none
}}
return [$net getName]
}}
foreach name {{kept free}} {{
puts "floorplan $name [supply $name VDD] [supply $name VSS]"
}}
set created [odb::dbInst_create $block [[ord::get_db] findMaster INV_X1] created]
global_connect
$created setDoNotTouch 1
foreach name {{kept created}} {{
puts "later $name [supply $name VDD] [supply $name VSS]"
}}
"""
def openroad():
return os.environ.get("OPENROAD_EXE") or shutil.which("openroad")
def run(script, cwd, env):
result = subprocess.run(
[openroad(), "-no_init", "-no_splash", "-exit", script],
cwd=cwd,
env=env,
capture_output=True,
text=True,
)
if result.returncode != 0:
raise AssertionError(
f"openroad {script} exited with {result.returncode}\n"
f"{result.stdout}{result.stderr}"
)
return result.stdout
@unittest.skipUnless(openroad(), "no openroad: set OPENROAD_EXE")
class GlobalConnectionsTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.tmp = tempfile.TemporaryDirectory()
cls.addClassCleanup(cls.tmp.cleanup)
cwd = cls.tmp.name
stub = os.path.join(cwd, "scripts")
os.mkdir(stub)
with open(os.path.join(stub, "load.tcl"), "w") as f:
f.write(LOAD)
with open(os.path.join(cwd, "top.v"), "w") as f:
f.write(DESIGN)
with open(os.path.join(cwd, "later.tcl"), "w") as f:
f.write(LATER)
with open(os.path.join(cwd, "pre_floorplan.tcl"), "w") as f:
f.write(PRE_FLOORPLAN)
env = dict(
os.environ,
SCRIPTS_DIR=stub,
PLATFORM_DIR=PLATFORM,
RESULTS_DIR=cwd,
REPORTS_DIR=cwd,
PRE_FLOORPLAN_TCL=os.path.join(cwd, "pre_floorplan.tcl"),
**ENV,
)
run(os.path.join(SCRIPTS, "floorplan.tcl"), cwd, env)
cls.supply = {}
for line in run("later.tcl", cwd, env).splitlines():
words = line.split()
if len(words) == 4 and words[0] in ("floorplan", "later"):
cls.supply[(words[0], words[1])] = words[2:]
def test_supply_pins_are_connected_at_floorplan(self):
self.assertEqual(self.supply[("floorplan", "free")], ["VDD", "VSS"])
def test_an_instance_the_pre_floorplan_hook_marks_is_connected(self):
self.assertEqual(self.supply[("floorplan", "kept")], ["VDD", "VSS"])
self.assertEqual(self.supply[("later", "kept")], ["VDD", "VSS"])
def test_rules_stay_in_the_database_for_a_later_step(self):
self.assertEqual(self.supply[("later", "created")], ["VDD", "VSS"])
if __name__ == "__main__":
unittest.main()
|