2013-10-16 09:16:06 -05:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
2021-06-07 17:39:36 -05:00
|
|
|
* Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-10-16 09:16:06 -05:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-10-16 09:16:06 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-05-04 15:48:02 -05:00
|
|
|
#include "kernel/yosys.h"
|
|
|
|
#include "kernel/sigtools.h"
|
2013-10-16 09:16:06 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
void split_portname_pair(std::string &port1, std::string &port2)
|
2013-10-26 15:27:40 -05:00
|
|
|
{
|
|
|
|
size_t pos = port1.find_first_of(':');
|
|
|
|
if (pos != std::string::npos) {
|
|
|
|
port2 = port1.substr(pos+1);
|
|
|
|
port1 = port1.substr(0, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-16 09:16:06 -05:00
|
|
|
struct IopadmapPass : public Pass {
|
2013-10-26 15:27:40 -05:00
|
|
|
IopadmapPass() : Pass("iopadmap", "technology mapping of i/o pads (or buffers)") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2013-10-16 09:16:06 -05:00
|
|
|
{
|
|
|
|
log("\n");
|
|
|
|
log(" iopadmap [options] [selection]\n");
|
|
|
|
log("\n");
|
|
|
|
log("Map module inputs/outputs to PAD cells from a library. This pass\n");
|
|
|
|
log("can only map to very simple PAD cells. Use 'techmap' to further map\n");
|
|
|
|
log("the resulting cells to more sophisticated PAD cells.\n");
|
|
|
|
log("\n");
|
2021-11-09 04:22:48 -06:00
|
|
|
log(" -inpad <celltype> <in_port>[:<ext_port>]\n");
|
2015-08-31 09:49:42 -05:00
|
|
|
log(" Map module input ports to the given cell type with the\n");
|
|
|
|
log(" given output port name. if a 2nd portname is given, the\n");
|
2022-02-02 05:14:38 -06:00
|
|
|
log(" signal is passed through the pad cell, using the 2nd\n");
|
2016-05-04 15:48:02 -05:00
|
|
|
log(" portname as the port facing the module port.\n");
|
2013-10-16 09:16:06 -05:00
|
|
|
log("\n");
|
2021-11-09 04:22:48 -06:00
|
|
|
log(" -outpad <celltype> <out_port>[:<ext_port>]\n");
|
|
|
|
log(" -inoutpad <celltype> <io_port>[:<ext_port>]\n");
|
2013-10-16 09:16:06 -05:00
|
|
|
log(" Similar to -inpad, but for output and inout ports.\n");
|
|
|
|
log("\n");
|
2021-11-09 04:22:48 -06:00
|
|
|
log(" -toutpad <celltype> <oe_port>:<out_port>[:<ext_port>]\n");
|
2016-05-04 15:48:02 -05:00
|
|
|
log(" Merges $_TBUF_ cells into the output pad cell. This takes precedence\n");
|
|
|
|
log(" over the other -outpad cell. The first portname is the enable input\n");
|
2021-11-09 04:22:48 -06:00
|
|
|
log(" of the tristate driver, which can be prefixed with `~` for negative\n");
|
|
|
|
log(" polarity enable.\n");
|
2016-05-04 15:48:02 -05:00
|
|
|
log("\n");
|
2021-11-09 04:22:48 -06:00
|
|
|
log(" -tinoutpad <celltype> <oe_port>:<in_port>:<out_port>[:<ext_port>]\n");
|
2016-05-04 15:48:02 -05:00
|
|
|
log(" Merges $_TBUF_ cells into the inout pad cell. This takes precedence\n");
|
|
|
|
log(" over the other -inoutpad cell. The first portname is the enable input\n");
|
|
|
|
log(" of the tristate driver and the 2nd portname is the internal output\n");
|
2021-11-09 04:22:48 -06:00
|
|
|
log(" buffering the external signal. Like with `-toutpad`, the enable can\n");
|
|
|
|
log(" be marked as negative polarity by prefixing the name with `~`.\n");
|
2016-05-04 15:48:02 -05:00
|
|
|
log("\n");
|
Add clock buffer insertion pass, improve iopadmap.
A few new attributes are defined for use in cell libraries:
- iopad_external_pin: marks PAD cell's external-facing pin. Pad
insertion will be skipped for ports that are already connected
to such a pin.
- clkbuf_sink: marks an input pin as a clock pin, requesting clock
buffer insertion.
- clkbuf_driver: marks an output pin as a clock buffer output pin.
Clock buffer insertion will be skipped for nets that are already
driven by such a pin.
All three are module attributes that should be set to a comma-separeted
list of pin names.
Clock buffer insertion itself works as follows:
1. All cell ports, starting from bottom up, can be marked as clock sinks
(requesting clock buffer insertion) or as clock buffer outputs.
2. If a wire in a given module is driven by a cell port that is a clock
buffer output, it is in turn also considered a clock buffer output.
3. If an input port in a non-top module is connected to a clock sink in a
contained cell, it is also in turn considered a clock sink.
4. If a wire in a module is driven by a non-clock-buffer cell, and is
also connected to a clock sink port in a contained cell, a clock
buffer is inserted in this module.
5. For the top module, a clock buffer is also inserted on input ports
connected to clock sinks, optionally with a special kind of input
PAD (such as IBUFG for Xilinx).
6. Clock buffer insertion on a given wire is skipped if the clkbuf_inhibit
attribute is set on it.
2019-08-12 10:57:43 -05:00
|
|
|
log(" -ignore <celltype> <portname>[:<portname>]*\n");
|
|
|
|
log(" Skips mapping inputs/outputs that are already connected to given\n");
|
|
|
|
log(" ports of the given cell. Can be used multiple times. This is in\n");
|
|
|
|
log(" addition to the cells specified as mapping targets.\n");
|
|
|
|
log("\n");
|
2013-10-16 09:16:06 -05:00
|
|
|
log(" -widthparam <param_name>\n");
|
|
|
|
log(" Use the specified parameter name to set the port width.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -nameparam <param_name>\n");
|
|
|
|
log(" Use the specified parameter to set the port name.\n");
|
|
|
|
log("\n");
|
2014-02-15 14:59:26 -06:00
|
|
|
log(" -bits\n");
|
|
|
|
log(" create individual bit-wide buffers even for ports that\n");
|
2015-01-06 07:37:50 -06:00
|
|
|
log(" are wider. (the default behavior is to create word-wide\n");
|
|
|
|
log(" buffers using -widthparam to set the word size on the cell.)\n");
|
2014-02-15 14:59:26 -06:00
|
|
|
log("\n");
|
2016-05-04 15:48:02 -05:00
|
|
|
log("Tristate PADS (-toutpad, -tinoutpad) always operate in -bits mode.\n");
|
|
|
|
log("\n");
|
2013-10-16 09:16:06 -05:00
|
|
|
}
|
2020-03-02 14:40:09 -06:00
|
|
|
|
|
|
|
void module_queue(Design *design, Module *module, std::vector<Module *> &modules_sorted, pool<Module *> &modules_processed) {
|
|
|
|
if (modules_processed.count(module))
|
|
|
|
return;
|
|
|
|
for (auto cell : module->cells()) {
|
|
|
|
Module *submodule = design->module(cell->type);
|
|
|
|
if (!submodule)
|
|
|
|
continue;
|
|
|
|
module_queue(design, submodule, modules_sorted, modules_processed);
|
|
|
|
}
|
|
|
|
modules_sorted.push_back(module);
|
|
|
|
modules_processed.insert(module);
|
|
|
|
}
|
|
|
|
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2013-10-16 09:16:06 -05:00
|
|
|
{
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Executing IOPADMAP pass (mapping inputs/outputs to IO-PAD cells).\n");
|
2013-10-16 09:16:06 -05:00
|
|
|
|
2019-12-04 01:44:08 -06:00
|
|
|
std::string inpad_celltype, inpad_portname_o, inpad_portname_pad;
|
|
|
|
std::string outpad_celltype, outpad_portname_i, outpad_portname_pad;
|
|
|
|
std::string inoutpad_celltype, inoutpad_portname_io, inoutpad_portname_pad;
|
|
|
|
std::string toutpad_celltype, toutpad_portname_oe, toutpad_portname_i, toutpad_portname_pad;
|
|
|
|
std::string tinoutpad_celltype, tinoutpad_portname_oe, tinoutpad_portname_o, tinoutpad_portname_i, tinoutpad_portname_pad;
|
2021-11-09 04:22:48 -06:00
|
|
|
bool toutpad_neg_oe = false, tinoutpad_neg_oe = false;
|
2013-10-16 09:16:06 -05:00
|
|
|
std::string widthparam, nameparam;
|
Add clock buffer insertion pass, improve iopadmap.
A few new attributes are defined for use in cell libraries:
- iopad_external_pin: marks PAD cell's external-facing pin. Pad
insertion will be skipped for ports that are already connected
to such a pin.
- clkbuf_sink: marks an input pin as a clock pin, requesting clock
buffer insertion.
- clkbuf_driver: marks an output pin as a clock buffer output pin.
Clock buffer insertion will be skipped for nets that are already
driven by such a pin.
All three are module attributes that should be set to a comma-separeted
list of pin names.
Clock buffer insertion itself works as follows:
1. All cell ports, starting from bottom up, can be marked as clock sinks
(requesting clock buffer insertion) or as clock buffer outputs.
2. If a wire in a given module is driven by a cell port that is a clock
buffer output, it is in turn also considered a clock buffer output.
3. If an input port in a non-top module is connected to a clock sink in a
contained cell, it is also in turn considered a clock sink.
4. If a wire in a module is driven by a non-clock-buffer cell, and is
also connected to a clock sink port in a contained cell, a clock
buffer is inserted in this module.
5. For the top module, a clock buffer is also inserted on input ports
connected to clock sinks, optionally with a special kind of input
PAD (such as IBUFG for Xilinx).
6. Clock buffer insertion on a given wire is skipped if the clkbuf_inhibit
attribute is set on it.
2019-08-12 10:57:43 -05:00
|
|
|
pool<pair<IdString, IdString>> ignore;
|
2014-02-15 14:59:26 -06:00
|
|
|
bool flag_bits = false;
|
2013-10-16 09:16:06 -05:00
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
|
|
|
std::string arg = args[argidx];
|
|
|
|
if (arg == "-inpad" && argidx+2 < args.size()) {
|
|
|
|
inpad_celltype = args[++argidx];
|
2019-12-04 01:44:08 -06:00
|
|
|
inpad_portname_o = args[++argidx];
|
|
|
|
split_portname_pair(inpad_portname_o, inpad_portname_pad);
|
2013-10-16 09:16:06 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-outpad" && argidx+2 < args.size()) {
|
|
|
|
outpad_celltype = args[++argidx];
|
2019-12-04 01:44:08 -06:00
|
|
|
outpad_portname_i = args[++argidx];
|
|
|
|
split_portname_pair(outpad_portname_i, outpad_portname_pad);
|
2013-10-16 09:16:06 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-inoutpad" && argidx+2 < args.size()) {
|
|
|
|
inoutpad_celltype = args[++argidx];
|
2019-12-04 01:44:08 -06:00
|
|
|
inoutpad_portname_io = args[++argidx];
|
|
|
|
split_portname_pair(inoutpad_portname_io, inoutpad_portname_pad);
|
2013-10-16 09:16:06 -05:00
|
|
|
continue;
|
|
|
|
}
|
2016-05-04 15:48:02 -05:00
|
|
|
if (arg == "-toutpad" && argidx+2 < args.size()) {
|
|
|
|
toutpad_celltype = args[++argidx];
|
2019-12-04 01:44:08 -06:00
|
|
|
toutpad_portname_oe = args[++argidx];
|
|
|
|
split_portname_pair(toutpad_portname_oe, toutpad_portname_i);
|
|
|
|
split_portname_pair(toutpad_portname_i, toutpad_portname_pad);
|
2021-11-09 04:22:48 -06:00
|
|
|
if (toutpad_portname_oe[0] == '~') {
|
|
|
|
toutpad_neg_oe = true;
|
|
|
|
toutpad_portname_oe = toutpad_portname_oe.substr(1);
|
|
|
|
}
|
2016-05-04 15:48:02 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-tinoutpad" && argidx+2 < args.size()) {
|
|
|
|
tinoutpad_celltype = args[++argidx];
|
2019-12-04 01:44:08 -06:00
|
|
|
tinoutpad_portname_oe = args[++argidx];
|
|
|
|
split_portname_pair(tinoutpad_portname_oe, tinoutpad_portname_o);
|
|
|
|
split_portname_pair(tinoutpad_portname_o, tinoutpad_portname_i);
|
|
|
|
split_portname_pair(tinoutpad_portname_i, tinoutpad_portname_pad);
|
2021-11-10 07:55:28 -06:00
|
|
|
if (tinoutpad_portname_oe[0] == '~') {
|
2021-11-09 04:22:48 -06:00
|
|
|
tinoutpad_neg_oe = true;
|
|
|
|
tinoutpad_portname_oe = tinoutpad_portname_oe.substr(1);
|
|
|
|
}
|
2016-05-04 15:48:02 -05:00
|
|
|
continue;
|
|
|
|
}
|
Add clock buffer insertion pass, improve iopadmap.
A few new attributes are defined for use in cell libraries:
- iopad_external_pin: marks PAD cell's external-facing pin. Pad
insertion will be skipped for ports that are already connected
to such a pin.
- clkbuf_sink: marks an input pin as a clock pin, requesting clock
buffer insertion.
- clkbuf_driver: marks an output pin as a clock buffer output pin.
Clock buffer insertion will be skipped for nets that are already
driven by such a pin.
All three are module attributes that should be set to a comma-separeted
list of pin names.
Clock buffer insertion itself works as follows:
1. All cell ports, starting from bottom up, can be marked as clock sinks
(requesting clock buffer insertion) or as clock buffer outputs.
2. If a wire in a given module is driven by a cell port that is a clock
buffer output, it is in turn also considered a clock buffer output.
3. If an input port in a non-top module is connected to a clock sink in a
contained cell, it is also in turn considered a clock sink.
4. If a wire in a module is driven by a non-clock-buffer cell, and is
also connected to a clock sink port in a contained cell, a clock
buffer is inserted in this module.
5. For the top module, a clock buffer is also inserted on input ports
connected to clock sinks, optionally with a special kind of input
PAD (such as IBUFG for Xilinx).
6. Clock buffer insertion on a given wire is skipped if the clkbuf_inhibit
attribute is set on it.
2019-08-12 10:57:43 -05:00
|
|
|
if (arg == "-ignore" && argidx+2 < args.size()) {
|
|
|
|
std::string ignore_celltype = args[++argidx];
|
|
|
|
std::string ignore_portname = args[++argidx];
|
|
|
|
std::string ignore_portname2;
|
|
|
|
while (!ignore_portname.empty()) {
|
|
|
|
split_portname_pair(ignore_portname, ignore_portname2);
|
|
|
|
ignore.insert(make_pair(RTLIL::escape_id(ignore_celltype), RTLIL::escape_id(ignore_portname)));
|
|
|
|
|
|
|
|
ignore_portname = ignore_portname2;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2013-10-16 09:16:06 -05:00
|
|
|
if (arg == "-widthparam" && argidx+1 < args.size()) {
|
|
|
|
widthparam = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-nameparam" && argidx+1 < args.size()) {
|
|
|
|
nameparam = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-15 14:59:26 -06:00
|
|
|
if (arg == "-bits") {
|
|
|
|
flag_bits = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-10-16 09:16:06 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
2019-12-04 01:44:08 -06:00
|
|
|
if (!inpad_portname_pad.empty())
|
|
|
|
ignore.insert(make_pair(RTLIL::escape_id(inpad_celltype), RTLIL::escape_id(inpad_portname_pad)));
|
|
|
|
if (!outpad_portname_pad.empty())
|
|
|
|
ignore.insert(make_pair(RTLIL::escape_id(outpad_celltype), RTLIL::escape_id(outpad_portname_pad)));
|
|
|
|
if (!inoutpad_portname_pad.empty())
|
|
|
|
ignore.insert(make_pair(RTLIL::escape_id(inoutpad_celltype), RTLIL::escape_id(inoutpad_portname_pad)));
|
|
|
|
if (!toutpad_portname_pad.empty())
|
|
|
|
ignore.insert(make_pair(RTLIL::escape_id(toutpad_celltype), RTLIL::escape_id(toutpad_portname_pad)));
|
|
|
|
if (!tinoutpad_portname_pad.empty())
|
|
|
|
ignore.insert(make_pair(RTLIL::escape_id(tinoutpad_celltype), RTLIL::escape_id(tinoutpad_portname_pad)));
|
Add clock buffer insertion pass, improve iopadmap.
A few new attributes are defined for use in cell libraries:
- iopad_external_pin: marks PAD cell's external-facing pin. Pad
insertion will be skipped for ports that are already connected
to such a pin.
- clkbuf_sink: marks an input pin as a clock pin, requesting clock
buffer insertion.
- clkbuf_driver: marks an output pin as a clock buffer output pin.
Clock buffer insertion will be skipped for nets that are already
driven by such a pin.
All three are module attributes that should be set to a comma-separeted
list of pin names.
Clock buffer insertion itself works as follows:
1. All cell ports, starting from bottom up, can be marked as clock sinks
(requesting clock buffer insertion) or as clock buffer outputs.
2. If a wire in a given module is driven by a cell port that is a clock
buffer output, it is in turn also considered a clock buffer output.
3. If an input port in a non-top module is connected to a clock sink in a
contained cell, it is also in turn considered a clock sink.
4. If a wire in a module is driven by a non-clock-buffer cell, and is
also connected to a clock sink port in a contained cell, a clock
buffer is inserted in this module.
5. For the top module, a clock buffer is also inserted on input ports
connected to clock sinks, optionally with a special kind of input
PAD (such as IBUFG for Xilinx).
6. Clock buffer insertion on a given wire is skipped if the clkbuf_inhibit
attribute is set on it.
2019-08-12 10:57:43 -05:00
|
|
|
|
2020-03-02 14:40:09 -06:00
|
|
|
// Recursively collect list of (module, port, bit) triples that already have buffers.
|
Add clock buffer insertion pass, improve iopadmap.
A few new attributes are defined for use in cell libraries:
- iopad_external_pin: marks PAD cell's external-facing pin. Pad
insertion will be skipped for ports that are already connected
to such a pin.
- clkbuf_sink: marks an input pin as a clock pin, requesting clock
buffer insertion.
- clkbuf_driver: marks an output pin as a clock buffer output pin.
Clock buffer insertion will be skipped for nets that are already
driven by such a pin.
All three are module attributes that should be set to a comma-separeted
list of pin names.
Clock buffer insertion itself works as follows:
1. All cell ports, starting from bottom up, can be marked as clock sinks
(requesting clock buffer insertion) or as clock buffer outputs.
2. If a wire in a given module is driven by a cell port that is a clock
buffer output, it is in turn also considered a clock buffer output.
3. If an input port in a non-top module is connected to a clock sink in a
contained cell, it is also in turn considered a clock sink.
4. If a wire in a module is driven by a non-clock-buffer cell, and is
also connected to a clock sink port in a contained cell, a clock
buffer is inserted in this module.
5. For the top module, a clock buffer is also inserted on input ports
connected to clock sinks, optionally with a special kind of input
PAD (such as IBUFG for Xilinx).
6. Clock buffer insertion on a given wire is skipped if the clkbuf_inhibit
attribute is set on it.
2019-08-12 10:57:43 -05:00
|
|
|
|
2020-03-02 14:40:09 -06:00
|
|
|
pool<pair<IdString, pair<IdString, int>>> buf_ports;
|
|
|
|
|
|
|
|
// Process submodules before module using them.
|
|
|
|
std::vector<Module *> modules_sorted;
|
|
|
|
pool<Module *> modules_processed;
|
2015-02-25 16:01:42 -06:00
|
|
|
for (auto module : design->selected_modules())
|
2020-03-02 14:40:09 -06:00
|
|
|
module_queue(design, module, modules_sorted, modules_processed);
|
|
|
|
|
|
|
|
for (auto module : modules_sorted)
|
2013-10-16 09:16:06 -05:00
|
|
|
{
|
2020-03-02 14:40:09 -06:00
|
|
|
pool<SigBit> buf_bits;
|
|
|
|
SigMap sigmap(module);
|
|
|
|
|
|
|
|
// Collect explicitly-marked already-buffered SigBits.
|
|
|
|
for (auto wire : module->wires())
|
2020-04-02 11:51:32 -05:00
|
|
|
if (wire->get_bool_attribute(ID::iopad_external_pin) || ignore.count(make_pair(module->name, wire->name)))
|
2020-03-02 14:40:09 -06:00
|
|
|
for (int i = 0; i < GetSize(wire); i++)
|
|
|
|
buf_bits.insert(sigmap(SigBit(wire, i)));
|
2018-05-15 06:13:43 -05:00
|
|
|
|
2020-03-02 14:40:09 -06:00
|
|
|
// Collect SigBits connected to already-buffered ports.
|
2018-05-15 06:13:43 -05:00
|
|
|
for (auto cell : module->cells())
|
Add clock buffer insertion pass, improve iopadmap.
A few new attributes are defined for use in cell libraries:
- iopad_external_pin: marks PAD cell's external-facing pin. Pad
insertion will be skipped for ports that are already connected
to such a pin.
- clkbuf_sink: marks an input pin as a clock pin, requesting clock
buffer insertion.
- clkbuf_driver: marks an output pin as a clock buffer output pin.
Clock buffer insertion will be skipped for nets that are already
driven by such a pin.
All three are module attributes that should be set to a comma-separeted
list of pin names.
Clock buffer insertion itself works as follows:
1. All cell ports, starting from bottom up, can be marked as clock sinks
(requesting clock buffer insertion) or as clock buffer outputs.
2. If a wire in a given module is driven by a cell port that is a clock
buffer output, it is in turn also considered a clock buffer output.
3. If an input port in a non-top module is connected to a clock sink in a
contained cell, it is also in turn considered a clock sink.
4. If a wire in a module is driven by a non-clock-buffer cell, and is
also connected to a clock sink port in a contained cell, a clock
buffer is inserted in this module.
5. For the top module, a clock buffer is also inserted on input ports
connected to clock sinks, optionally with a special kind of input
PAD (such as IBUFG for Xilinx).
6. Clock buffer insertion on a given wire is skipped if the clkbuf_inhibit
attribute is set on it.
2019-08-12 10:57:43 -05:00
|
|
|
for (auto port : cell->connections())
|
2020-03-02 14:40:09 -06:00
|
|
|
for (int i = 0; i < port.second.size(); i++)
|
|
|
|
if (buf_ports.count(make_pair(cell->type, make_pair(port.first, i))))
|
|
|
|
buf_bits.insert(sigmap(port.second[i]));
|
|
|
|
|
|
|
|
// Now fill buf_ports.
|
|
|
|
for (auto wire : module->wires())
|
|
|
|
if (wire->port_input || wire->port_output)
|
|
|
|
for (int i = 0; i < GetSize(wire); i++)
|
|
|
|
if (buf_bits.count(sigmap(SigBit(wire, i)))) {
|
|
|
|
buf_ports.insert(make_pair(module->name, make_pair(wire->name, i)));
|
|
|
|
log("Marking already mapped port: %s.%s[%d].\n", log_id(module), log_id(wire), i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now do the actual buffer insertion.
|
|
|
|
|
|
|
|
for (auto module : design->selected_modules())
|
|
|
|
{
|
|
|
|
dict<Wire *, dict<int, pair<Cell *, IdString>>> rewrite_bits;
|
2022-06-06 19:18:08 -05:00
|
|
|
dict<SigSig, pool<int>> remove_conns;
|
2018-05-15 06:13:43 -05:00
|
|
|
|
2016-05-04 15:48:02 -05:00
|
|
|
if (!toutpad_celltype.empty() || !tinoutpad_celltype.empty())
|
|
|
|
{
|
2019-12-04 01:44:08 -06:00
|
|
|
dict<SigBit, Cell *> tbuf_bits;
|
2019-12-21 18:08:56 -06:00
|
|
|
pool<SigBit> driven_bits;
|
2022-06-06 19:18:08 -05:00
|
|
|
dict<SigBit, std::pair<SigSig, int>> z_conns;
|
2016-05-04 15:48:02 -05:00
|
|
|
|
2019-12-21 18:08:56 -06:00
|
|
|
// Gather tristate buffers and always-on drivers.
|
2016-05-04 15:48:02 -05:00
|
|
|
for (auto cell : module->cells())
|
2019-08-15 12:05:08 -05:00
|
|
|
if (cell->type == ID($_TBUF_)) {
|
2019-12-04 01:44:08 -06:00
|
|
|
SigBit bit = cell->getPort(ID::Y).as_bit();
|
|
|
|
tbuf_bits[bit] = cell;
|
2019-12-21 18:08:56 -06:00
|
|
|
} else {
|
|
|
|
for (auto port : cell->connections())
|
|
|
|
if (!cell->known() || cell->output(port.first))
|
|
|
|
for (auto bit : port.second)
|
|
|
|
driven_bits.insert(bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a wire is a target of an assignment, it is driven, unless the source is 'z.
|
|
|
|
for (auto &conn : module->connections())
|
|
|
|
for (int i = 0; i < GetSize(conn.first); i++) {
|
|
|
|
SigBit dstbit = conn.first[i];
|
|
|
|
SigBit srcbit = conn.second[i];
|
2020-03-30 08:35:31 -05:00
|
|
|
if (!srcbit.wire && srcbit.data == State::Sz) {
|
2022-06-06 19:18:08 -05:00
|
|
|
z_conns[dstbit] = {conn, i};
|
2019-12-21 18:08:56 -06:00
|
|
|
continue;
|
2020-03-30 08:35:31 -05:00
|
|
|
}
|
2019-12-21 18:08:56 -06:00
|
|
|
driven_bits.insert(dstbit);
|
2016-05-04 15:48:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto wire : module->selected_wires())
|
|
|
|
{
|
|
|
|
if (!wire->port_output)
|
|
|
|
continue;
|
|
|
|
|
2019-12-21 18:08:56 -06:00
|
|
|
// Don't handle inout ports if we have no suitable buffer type.
|
|
|
|
if (wire->port_input && tinoutpad_celltype.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// likewise for output ports.
|
|
|
|
if (!wire->port_input && toutpad_celltype.empty())
|
|
|
|
continue;
|
|
|
|
|
2016-05-04 15:48:02 -05:00
|
|
|
for (int i = 0; i < GetSize(wire); i++)
|
|
|
|
{
|
|
|
|
SigBit wire_bit(wire, i);
|
2019-12-21 18:08:56 -06:00
|
|
|
Cell *tbuf_cell = nullptr;
|
2016-05-04 15:48:02 -05:00
|
|
|
|
2020-03-02 14:40:09 -06:00
|
|
|
if (buf_ports.count(make_pair(module->name, make_pair(wire->name, i))))
|
2020-01-01 09:13:14 -06:00
|
|
|
continue;
|
|
|
|
|
2019-12-21 18:08:56 -06:00
|
|
|
if (tbuf_bits.count(wire_bit))
|
|
|
|
tbuf_cell = tbuf_bits.at(wire_bit);
|
2016-05-04 15:48:02 -05:00
|
|
|
|
2019-12-21 18:08:56 -06:00
|
|
|
SigBit en_sig;
|
|
|
|
SigBit data_sig;
|
|
|
|
bool is_driven = driven_bits.count(wire_bit);
|
2016-05-04 15:48:02 -05:00
|
|
|
|
2019-12-21 18:08:56 -06:00
|
|
|
if (tbuf_cell != nullptr) {
|
|
|
|
// Found a tristate buffer — use it.
|
2020-04-02 11:51:32 -05:00
|
|
|
en_sig = tbuf_cell->getPort(ID::E).as_bit();
|
2019-12-21 18:08:56 -06:00
|
|
|
data_sig = tbuf_cell->getPort(ID::A).as_bit();
|
|
|
|
} else if (is_driven) {
|
|
|
|
// No tristate buffer, but an always-on driver is present.
|
|
|
|
// If this is an inout port, we're creating a tinoutpad
|
|
|
|
// anyway, just with a constant 1 as enable.
|
|
|
|
if (!wire->port_input)
|
|
|
|
continue;
|
|
|
|
en_sig = SigBit(State::S1);
|
|
|
|
data_sig = wire_bit;
|
|
|
|
} else {
|
|
|
|
// No driver on a wire. Create a tristate pad with always-0
|
|
|
|
// enable.
|
|
|
|
en_sig = SigBit(State::S0);
|
|
|
|
data_sig = SigBit(State::Sx);
|
2022-06-06 19:18:08 -05:00
|
|
|
auto it = z_conns.find(wire_bit);
|
|
|
|
if (it != z_conns.end())
|
|
|
|
remove_conns[it->second.first].insert(it->second.second);
|
2019-12-21 18:08:56 -06:00
|
|
|
}
|
2016-05-04 15:48:02 -05:00
|
|
|
|
2019-12-21 18:08:56 -06:00
|
|
|
if (wire->port_input)
|
2016-05-04 15:48:02 -05:00
|
|
|
{
|
|
|
|
log("Mapping port %s.%s[%d] using %s.\n", log_id(module), log_id(wire), i, tinoutpad_celltype.c_str());
|
|
|
|
|
2020-03-02 03:54:37 -06:00
|
|
|
Cell *cell = module->addCell(
|
|
|
|
module->uniquify(stringf("$iopadmap$%s.%s[%d]", log_id(module), log_id(wire), i)),
|
|
|
|
RTLIL::escape_id(tinoutpad_celltype));
|
2016-05-04 15:48:02 -05:00
|
|
|
|
2021-11-09 04:22:48 -06:00
|
|
|
if (tinoutpad_neg_oe)
|
|
|
|
en_sig = module->NotGate(NEW_ID, en_sig);
|
2019-12-04 01:44:08 -06:00
|
|
|
cell->setPort(RTLIL::escape_id(tinoutpad_portname_oe), en_sig);
|
2019-08-15 16:51:12 -05:00
|
|
|
cell->attributes[ID::keep] = RTLIL::Const(1);
|
2016-05-04 15:48:02 -05:00
|
|
|
|
2019-12-21 18:08:56 -06:00
|
|
|
if (tbuf_cell) {
|
|
|
|
module->remove(tbuf_cell);
|
|
|
|
cell->setPort(RTLIL::escape_id(tinoutpad_portname_o), wire_bit);
|
|
|
|
cell->setPort(RTLIL::escape_id(tinoutpad_portname_i), data_sig);
|
|
|
|
} else if (is_driven) {
|
|
|
|
cell->setPort(RTLIL::escape_id(tinoutpad_portname_i), wire_bit);
|
|
|
|
} else {
|
|
|
|
cell->setPort(RTLIL::escape_id(tinoutpad_portname_o), wire_bit);
|
|
|
|
cell->setPort(RTLIL::escape_id(tinoutpad_portname_i), data_sig);
|
|
|
|
}
|
2019-12-04 01:44:08 -06:00
|
|
|
if (!tinoutpad_portname_pad.empty())
|
|
|
|
rewrite_bits[wire][i] = make_pair(cell, RTLIL::escape_id(tinoutpad_portname_pad));
|
2019-12-21 18:08:56 -06:00
|
|
|
} else {
|
2016-05-04 15:48:02 -05:00
|
|
|
log("Mapping port %s.%s[%d] using %s.\n", log_id(module), log_id(wire), i, toutpad_celltype.c_str());
|
|
|
|
|
2020-03-02 03:54:37 -06:00
|
|
|
Cell *cell = module->addCell(
|
|
|
|
module->uniquify(stringf("$iopadmap$%s.%s[%d]", log_id(module), log_id(wire), i)),
|
|
|
|
RTLIL::escape_id(toutpad_celltype));
|
2016-05-04 15:48:02 -05:00
|
|
|
|
2021-11-09 04:22:48 -06:00
|
|
|
if (toutpad_neg_oe)
|
|
|
|
en_sig = module->NotGate(NEW_ID, en_sig);
|
2019-12-04 01:44:08 -06:00
|
|
|
cell->setPort(RTLIL::escape_id(toutpad_portname_oe), en_sig);
|
|
|
|
cell->setPort(RTLIL::escape_id(toutpad_portname_i), data_sig);
|
2019-08-15 16:51:12 -05:00
|
|
|
cell->attributes[ID::keep] = RTLIL::Const(1);
|
2016-05-04 15:48:02 -05:00
|
|
|
|
2019-12-21 18:08:56 -06:00
|
|
|
if (tbuf_cell) {
|
|
|
|
module->remove(tbuf_cell);
|
|
|
|
module->connect(wire_bit, data_sig);
|
|
|
|
}
|
2019-12-04 01:44:08 -06:00
|
|
|
if (!toutpad_portname_pad.empty())
|
|
|
|
rewrite_bits[wire][i] = make_pair(cell, RTLIL::escape_id(toutpad_portname_pad));
|
2016-05-04 15:48:02 -05:00
|
|
|
}
|
2020-03-02 14:40:09 -06:00
|
|
|
buf_ports.insert(make_pair(module->name, make_pair(wire->name, i)));
|
2016-05-04 15:48:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 16:01:42 -06:00
|
|
|
for (auto wire : module->selected_wires())
|
2013-10-16 09:16:06 -05:00
|
|
|
{
|
2015-02-25 16:01:42 -06:00
|
|
|
if (!wire->port_id)
|
2013-10-16 09:16:06 -05:00
|
|
|
continue;
|
|
|
|
|
2019-12-04 01:44:08 -06:00
|
|
|
std::string celltype, portname_int, portname_pad;
|
2016-05-04 15:48:02 -05:00
|
|
|
pool<int> skip_bit_indices;
|
|
|
|
|
2018-05-15 06:13:43 -05:00
|
|
|
for (int i = 0; i < GetSize(wire); i++)
|
2020-03-02 14:40:09 -06:00
|
|
|
if (buf_ports.count(make_pair(module->name, make_pair(wire->name, i))))
|
2018-05-15 06:13:43 -05:00
|
|
|
skip_bit_indices.insert(i);
|
|
|
|
|
|
|
|
if (GetSize(wire) == GetSize(skip_bit_indices))
|
|
|
|
continue;
|
|
|
|
|
2013-10-16 09:16:06 -05:00
|
|
|
if (wire->port_input && !wire->port_output) {
|
|
|
|
if (inpad_celltype.empty()) {
|
|
|
|
log("Don't map input port %s.%s: Missing option -inpad.\n", RTLIL::id2cstr(module->name), RTLIL::id2cstr(wire->name));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
celltype = inpad_celltype;
|
2019-12-04 01:44:08 -06:00
|
|
|
portname_int = inpad_portname_o;
|
|
|
|
portname_pad = inpad_portname_pad;
|
2013-10-16 09:16:06 -05:00
|
|
|
} else
|
|
|
|
if (!wire->port_input && wire->port_output) {
|
|
|
|
if (outpad_celltype.empty()) {
|
|
|
|
log("Don't map output port %s.%s: Missing option -outpad.\n", RTLIL::id2cstr(module->name), RTLIL::id2cstr(wire->name));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
celltype = outpad_celltype;
|
2019-12-04 01:44:08 -06:00
|
|
|
portname_int = outpad_portname_i;
|
|
|
|
portname_pad = outpad_portname_pad;
|
2013-10-16 09:16:06 -05:00
|
|
|
} else
|
|
|
|
if (wire->port_input && wire->port_output) {
|
|
|
|
if (inoutpad_celltype.empty()) {
|
|
|
|
log("Don't map inout port %s.%s: Missing option -inoutpad.\n", RTLIL::id2cstr(module->name), RTLIL::id2cstr(wire->name));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
celltype = inoutpad_celltype;
|
2019-12-04 01:44:08 -06:00
|
|
|
portname_int = inoutpad_portname_io;
|
|
|
|
portname_pad = inoutpad_portname_pad;
|
2013-10-16 09:16:06 -05:00
|
|
|
} else
|
|
|
|
log_abort();
|
|
|
|
|
2014-02-15 14:59:26 -06:00
|
|
|
if (!flag_bits && wire->width != 1 && widthparam.empty()) {
|
|
|
|
log("Don't map multi-bit port %s.%s: Missing option -widthparam or -bits.\n", RTLIL::id2cstr(module->name), RTLIL::id2cstr(wire->name));
|
2013-10-16 09:16:06 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-10-26 15:27:40 -05:00
|
|
|
log("Mapping port %s.%s using %s.\n", RTLIL::id2cstr(module->name), RTLIL::id2cstr(wire->name), celltype.c_str());
|
2013-10-16 09:16:06 -05:00
|
|
|
|
2014-02-15 14:59:26 -06:00
|
|
|
if (flag_bits)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < wire->width; i++)
|
|
|
|
{
|
2019-12-04 01:44:08 -06:00
|
|
|
if (skip_bit_indices.count(i))
|
2016-05-04 15:48:02 -05:00
|
|
|
continue;
|
2019-12-04 01:44:08 -06:00
|
|
|
|
|
|
|
SigBit wire_bit(wire, i);
|
2016-05-04 15:48:02 -05:00
|
|
|
|
2020-03-02 03:54:37 -06:00
|
|
|
RTLIL::Cell *cell = module->addCell(
|
|
|
|
module->uniquify(stringf("$iopadmap$%s.%s", log_id(module->name), log_id(wire->name))),
|
|
|
|
RTLIL::escape_id(celltype));
|
2019-12-04 01:44:08 -06:00
|
|
|
cell->setPort(RTLIL::escape_id(portname_int), wire_bit);
|
|
|
|
|
|
|
|
if (!portname_pad.empty())
|
|
|
|
rewrite_bits[wire][i] = make_pair(cell, RTLIL::escape_id(portname_pad));
|
2014-02-15 14:59:26 -06:00
|
|
|
if (!widthparam.empty())
|
|
|
|
cell->parameters[RTLIL::escape_id(widthparam)] = RTLIL::Const(1);
|
|
|
|
if (!nameparam.empty())
|
|
|
|
cell->parameters[RTLIL::escape_id(nameparam)] = RTLIL::Const(stringf("%s[%d]", RTLIL::id2cstr(wire->name), i));
|
2019-08-15 16:51:12 -05:00
|
|
|
cell->attributes[ID::keep] = RTLIL::Const(1);
|
2014-02-15 14:59:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-02 03:54:37 -06:00
|
|
|
RTLIL::Cell *cell = module->addCell(
|
|
|
|
module->uniquify(stringf("$iopadmap$%s.%s", log_id(module->name), log_id(wire->name))),
|
|
|
|
RTLIL::escape_id(celltype));
|
2019-12-04 01:44:08 -06:00
|
|
|
cell->setPort(RTLIL::escape_id(portname_int), RTLIL::SigSpec(wire));
|
|
|
|
|
|
|
|
if (!portname_pad.empty()) {
|
|
|
|
RTLIL::Wire *new_wire = NULL;
|
2020-03-02 03:54:37 -06:00
|
|
|
new_wire = module->addWire(
|
|
|
|
module->uniquify(stringf("$iopadmap$%s", log_id(wire))),
|
|
|
|
wire);
|
2019-12-04 01:44:08 -06:00
|
|
|
module->swap_names(new_wire, wire);
|
|
|
|
wire->attributes.clear();
|
|
|
|
cell->setPort(RTLIL::escape_id(portname_pad), RTLIL::SigSpec(new_wire));
|
|
|
|
}
|
2014-02-15 14:59:26 -06:00
|
|
|
if (!widthparam.empty())
|
|
|
|
cell->parameters[RTLIL::escape_id(widthparam)] = RTLIL::Const(wire->width);
|
|
|
|
if (!nameparam.empty())
|
|
|
|
cell->parameters[RTLIL::escape_id(nameparam)] = RTLIL::Const(RTLIL::id2cstr(wire->name));
|
2019-08-15 16:51:12 -05:00
|
|
|
cell->attributes[ID::keep] = RTLIL::Const(1);
|
2014-02-15 14:59:26 -06:00
|
|
|
}
|
2013-10-16 09:16:06 -05:00
|
|
|
|
2019-12-04 01:44:08 -06:00
|
|
|
if (!rewrite_bits.count(wire)) {
|
|
|
|
wire->port_id = 0;
|
|
|
|
wire->port_input = false;
|
|
|
|
wire->port_output = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 08:35:31 -05:00
|
|
|
if (!remove_conns.empty()) {
|
|
|
|
std::vector<SigSig> new_conns;
|
2022-06-06 19:18:08 -05:00
|
|
|
for (auto &conn : module->connections()) {
|
|
|
|
auto it = remove_conns.find(conn);
|
|
|
|
if (it == remove_conns.end()) {
|
2020-03-30 08:35:31 -05:00
|
|
|
new_conns.push_back(conn);
|
2022-06-06 19:18:08 -05:00
|
|
|
} else {
|
|
|
|
SigSpec lhs, rhs;
|
|
|
|
for (int i = 0; i < GetSize(conn.first); i++) {
|
|
|
|
if (!it->second.count(i)) {
|
|
|
|
lhs.append(conn.first[i]);
|
|
|
|
rhs.append(conn.second[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
new_conns.push_back(SigSig(lhs, rhs));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2020-03-30 08:35:31 -05:00
|
|
|
module->new_connections(new_conns);
|
|
|
|
}
|
|
|
|
|
2019-12-04 01:44:08 -06:00
|
|
|
for (auto &it : rewrite_bits) {
|
|
|
|
RTLIL::Wire *wire = it.first;
|
2020-03-02 03:54:37 -06:00
|
|
|
RTLIL::Wire *new_wire = module->addWire(
|
|
|
|
module->uniquify(stringf("$iopadmap$%s", log_id(wire))),
|
|
|
|
wire);
|
2019-12-04 01:44:08 -06:00
|
|
|
module->swap_names(new_wire, wire);
|
2020-02-13 16:57:06 -06:00
|
|
|
wire->attributes.clear();
|
2019-12-04 01:44:08 -06:00
|
|
|
for (int i = 0; i < wire->width; i++)
|
|
|
|
{
|
|
|
|
SigBit wire_bit(wire, i);
|
|
|
|
if (!it.second.count(i)) {
|
2020-02-13 16:57:06 -06:00
|
|
|
if (wire->port_output)
|
2019-12-04 01:44:08 -06:00
|
|
|
module->connect(SigSpec(new_wire, i), SigSpec(wire, i));
|
2020-02-13 16:57:06 -06:00
|
|
|
else
|
2019-12-04 01:44:08 -06:00
|
|
|
module->connect(SigSpec(wire, i), SigSpec(new_wire, i));
|
|
|
|
} else {
|
|
|
|
auto &new_conn = it.second.at(i);
|
|
|
|
new_conn.first->setPort(new_conn.second, RTLIL::SigSpec(new_wire, i));
|
2020-02-13 16:57:06 -06:00
|
|
|
}
|
|
|
|
}
|
2020-02-13 14:05:14 -06:00
|
|
|
|
2020-02-13 16:57:06 -06:00
|
|
|
if (wire->port_output) {
|
2020-04-02 11:51:32 -05:00
|
|
|
auto jt = new_wire->attributes.find(ID::init);
|
2020-02-13 16:57:06 -06:00
|
|
|
// For output ports, move \init attributes from old wire to new wire
|
|
|
|
if (jt != new_wire->attributes.end()) {
|
2020-04-02 11:51:32 -05:00
|
|
|
wire->attributes[ID::init] = std::move(jt->second);
|
2020-02-13 16:57:06 -06:00
|
|
|
new_wire->attributes.erase(jt);
|
2019-12-04 01:44:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-16 09:16:06 -05:00
|
|
|
wire->port_id = 0;
|
|
|
|
wire->port_input = false;
|
|
|
|
wire->port_output = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
module->fixup_ports();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} IopadmapPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|