Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read_liberty extensions #4682

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions frontends/liberty/liberty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ struct LibertyFrontend : public Frontend {
log(" -ignore_miss_data_latch\n");
log(" ignore latches with missing data and/or enable pins\n");
log("\n");
log(" -ignore_buses\n");
log(" ignore cells with bus interfaces (wide ports)\n");
log("\n");
log(" -setattr <attribute_name>\n");
log(" set the specified attribute (to the value 1) on all loaded modules\n");
log("\n");
Expand All @@ -478,6 +481,7 @@ struct LibertyFrontend : public Frontend {
bool flag_ignore_miss_func = false;
bool flag_ignore_miss_dir = false;
bool flag_ignore_miss_data_latch = false;
bool flag_ignore_buses = false;
bool flag_unit_delay = false;
std::vector<std::string> attributes;

Expand Down Expand Up @@ -514,6 +518,10 @@ struct LibertyFrontend : public Frontend {
flag_ignore_miss_data_latch = true;
continue;
}
if (arg == "-ignore_buses") {
flag_ignore_buses = true;
continue;
}
if (arg == "-setattr" && argidx+1 < args.size()) {
attributes.push_back(RTLIL::escape_id(args[++argidx]));
continue;
Expand Down Expand Up @@ -542,27 +550,13 @@ struct LibertyFrontend : public Frontend {
if (cell->id != "cell" || cell->args.size() != 1)
continue;

std::string cell_name = RTLIL::escape_id(cell->args.at(0));

if (design->has(cell_name)) {
Module *existing_mod = design->module(cell_name);
if (!flag_nooverwrite && !flag_overwrite && !existing_mod->get_bool_attribute(ID::blackbox)) {
log_error("Re-definition of cell/module %s!\n", log_id(cell_name));
} else if (flag_nooverwrite) {
log("Ignoring re-definition of module %s.\n", log_id(cell_name));
continue;
} else {
log("Replacing existing%s module %s.\n", existing_mod->get_bool_attribute(ID::blackbox) ? " blackbox" : "", log_id(cell_name));
design->remove(existing_mod);
}
}

// log("Processing cell type %s.\n", RTLIL::unescape_id(cell_name).c_str());

std::map<std::string, std::tuple<int, int, bool>> type_map = global_type_map;
parse_type_map(type_map, cell);

RTLIL::Module *module = new RTLIL::Module;
std::string cell_name = RTLIL::escape_id(cell->args.at(0));
module->name = cell_name;

if (flag_lib)
Expand All @@ -571,6 +565,10 @@ struct LibertyFrontend : public Frontend {
if (flag_wb)
module->set_bool_attribute(ID::whitebox);

const LibertyAst *area = cell->find("area");
if (area)
module->attributes[ID::area] = area->value;

for (auto &attr : attributes)
module->attributes[attr] = 1;

Expand All @@ -595,6 +593,12 @@ struct LibertyFrontend : public Frontend {

if (node->id == "bus" && node->args.size() == 1)
{
if (flag_ignore_buses) {
log("Ignoring cell %s with a bus interface %s.\n", log_id(module->name), node->args.at(0).c_str());
delete module;
goto skip_cell;
}

if (!flag_lib)
log_error("Error in cell %s: bus interfaces are only supported in -lib mode.\n", log_id(cell_name));

Expand Down Expand Up @@ -662,6 +666,10 @@ struct LibertyFrontend : public Frontend {
RTLIL::Wire *wire = module->wires_.at(RTLIL::escape_id(node->args.at(0)));
log_assert(wire);

const LibertyAst *capacitance = node->find("capacitance");
if (capacitance)
wire->attributes[ID::capacitance] = capacitance->value;

if (dir && dir->value == "inout") {
wire->port_input = true;
wire->port_output = true;
Expand Down Expand Up @@ -739,6 +747,20 @@ struct LibertyFrontend : public Frontend {
}
}

if (design->has(cell_name)) {
Module *existing_mod = design->module(cell_name);
if (!flag_nooverwrite && !flag_overwrite && !existing_mod->get_bool_attribute(ID::blackbox)) {
log_error("Re-definition of cell/module %s!\n", log_id(cell_name));
} else if (flag_nooverwrite) {
log("Ignoring re-definition of module %s.\n", log_id(cell_name));
delete module;
goto skip_cell;
} else {
log("Replacing existing%s module %s.\n", existing_mod->get_bool_attribute(ID::blackbox) ? " blackbox" : "", log_id(cell_name));
design->remove(existing_mod);
}
}

module->fixup_ports();
design->add(module);
cell_count++;
Expand Down
2 changes: 2 additions & 0 deletions kernel/constids.inc
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,5 @@ X(X)
X(xprop_decoder)
X(Y)
X(Y_WIDTH)
X(area)
X(capacitance)
2 changes: 1 addition & 1 deletion tests/liberty/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.log
*.filtered
/*.filtered
*.verilogsim
2 changes: 2 additions & 0 deletions tests/liberty/foundry_data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.lib
*.lib.filtered
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/liberty/foundry_data/rules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-wire_load
-wire_load_selection
-default_wire_load
-default_wire_load_area
-default_wire_load_capacitance
-default_wire_load_mode
-default_wire_load_resistance
-default_cell_leakage_power
-default_wire_load_selection
-default_leakage_power_density
-lu_table_template
-power_lut_template
-leakage_power
-cell_leakage_power
-leakage_power
-internal_power
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/liberty/options_test.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Test memory macro gets ignored due to -ignore_buses
read_verilog -noblackbox <<EOF
module RM_IHPSG13_1P_64x64_c2_bm_bist();
endmodule
EOF
read_liberty -lib -ignore_buses foundry_data/RM_IHPSG13_1P_64x64_c2_bm_bist_typ_1p20V_25C.lib.filtered.gz

# Test memory macro doesn't get ignored without -ignore_buses
# and check the area and capacitance attributes are populated
design -reset
read_liberty -lib foundry_data/RM_IHPSG13_1P_64x64_c2_bm_bist_typ_1p20V_25C.lib.filtered.gz
select -assert-mod-count 1 =RM_IHPSG13_1P_64x64_c2_bm_bist =A:area=50489.1328 %i
select -assert-any =*/i:A_BIST_EN =*/a:capacitance=0.00401111 %i

# Test import of unit delay arcs
design -reset
read_liberty -wb -unit_delay -ignore_miss_func foundry_data/sg13g2_stdcell_typ_1p20V_25C.lib.filtered.gz

# A->Y arc on nand2_1 exists
select -assert-any =sg13g2_nand2_1/i:A %co1:+$specify2[SRC] =sg13g2_nand2_1/o:Y %co1:+$specify2[DST] %i

# D->Q arc on sdfbbp_1 doesn't
select -assert-none =sg13g2_sdfbbp_1/i:D %co1:+$specify2[SRC] =sg13g2_nand2_1/o:Q %co1:+$specify2[DST] %i
3 changes: 0 additions & 3 deletions tests/liberty/unit_delay.ys

This file was deleted.

Loading