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

Enabled BLIF buffer elimination in preparation for InOuts #1520

Open
wants to merge 2 commits into
base: master
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
98 changes: 54 additions & 44 deletions ODIN_II/SRC/output_blif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,26 @@ static bool warn_undriven(nnode_t* node, nnet_t* net) {
return false;
}

// TODO Uncomment this for In Outs
//static void merge_with_inputs(nnode_t* node, long pin_idx) {
// oassert(pin_idx < node->num_input_pins);
// nnet_t* net = node->input_pins[pin_idx]->net;
// warn_undriven(node, net);
// // Merge node with all inputs with fanout of 1
// if (net->num_fanout_pins <= 1) {
// for (int i = 0; i < net->num_driver_pins; i++) {
// npin_t* driver = net->driver_pins[i];
// if (driver->name != NULL && ((driver->node->type == MULTIPLY) || (driver->node->type == HARD_IP) || (driver->node->type == MEMORY) || (driver->node->type == ADD) || (driver->node->type == MINUS))) {
// vtr::free(driver->name);
// driver->name = vtr::strdup(node->name);
// } else {
// vtr::free(driver->node->name);
// driver->node->name = vtr::strdup(node->name);
// }
// }
// }
//}
static void merge_with_inputs(nnode_t* node, long pin_idx) {
oassert(pin_idx < node->num_input_pins);
oassert(node->type == OUTPUT_NODE);
nnet_t* net = node->input_pins[pin_idx]->net;
warn_undriven(node, net);
// Merge node with all inputs with fanout of 1
if (net->num_fanout_pins <= 1) {
for (int i = 0; i < net->num_driver_pins; i++) {
npin_t* driver = net->driver_pins[i];
if (driver->name != NULL && ((driver->node->type == MULTIPLY) || (driver->node->type == HARD_IP) || (driver->node->type == MEMORY) || (driver->node->type == ADD) || (driver->node->type == MINUS))) {
Copy link
Contributor

@jeanlego jeanlego Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't forsee this being used for anything else but output. can you assert that node->type is OUTPUT_NODE
I would rather not see this used anywhere else in the future unless theres a good reason for it, so guarding it should make that clear

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you mean the input node? The driver can be anything that drives an output yeah?

vtr::free(driver->name);
driver->name = vtr::strdup(node->name);
} else {
vtr::free(driver->node->name);
oassert(driver->node->num_output_pins == 1);
driver->node->name = vtr::strdup(node->name);
}
}
}
}

static void print_net_driver(FILE* out, nnode_t* node, nnet_t* net, long driver_idx) {
oassert(driver_idx < net->num_driver_pins);
Expand All @@ -105,6 +106,7 @@ static void print_net_driver(FILE* out, nnode_t* node, nnet_t* net, long driver_
if (driver->name != NULL && ((driver->node->type == MULTIPLY) || (driver->node->type == HARD_IP) || (driver->node->type == MEMORY) || (driver->node->type == ADD) || (driver->node->type == MINUS))) {
fprintf(out, " %s", driver->name);
} else {
oassert(driver->node->num_output_pins == 1);
fprintf(out, " %s", driver->node->name);
}
}
Expand Down Expand Up @@ -133,21 +135,27 @@ static void print_output_pin(FILE* out, nnode_t* node) {
fprintf(out, " %s", node->name);
}

static char* buffer_multi_drivers(FILE* out, nnode_t* node, long pin_idx)
{
nnet_t* net = node->input_pins[pin_idx]->net;
if (net->num_driver_pins > 1) {
char* name = op_node_name(BUF_NODE, node->name);
// Assign each driver to the implicit buffer
for (int j = 0; j < net->num_driver_pins; j++) {
fprintf(out, ".names");
print_net_driver(out, node, net, j);
fprintf(out, " %s\n1 1\n\n", name);
}
return name;
}
return NULL;
}

static void print_dot_names_header(FILE* out, nnode_t* node) {
char** names = (char**)vtr::calloc(node->num_input_pins, sizeof(char*));

// Create an implicit buffer if there are multiple drivers to the component
for (int i = 0; i < node->num_input_pins; i++) {
nnet_t* input_net = node->input_pins[i]->net;
if (input_net->num_driver_pins > 1) {
names[i] = op_node_name(BUF_NODE, node->name);
// Assign each driver to the implicit buffer
for (int j = 0; j < input_net->num_driver_pins; j++) {
fprintf(out, ".names");
print_net_driver(out, node, input_net, j);
fprintf(out, " %s\n1 1\n\n", names[i]);
}
}
names[i] = buffer_multi_drivers(out, node, i);
}

// Print the actual header
Expand Down Expand Up @@ -221,14 +229,13 @@ void output_blif(FILE* out, netlist_t* netlist) {
fprintf(out, "\n.names gnd\n.names unconn\n.names vcc\n1\n");
fprintf(out, "\n");

// TODO Uncomment this for In Outs
// connect all the outputs up to the last gate
// for (long i = 0; i < netlist->num_top_output_nodes; i++) {
// nnode_t* node = netlist->top_output_nodes[i];
// for (int j = 0; j < node->num_input_pins; j++) {
// merge_with_inputs(node, j);
// }
// }
for (long i = 0; i < netlist->num_top_output_nodes; i++) {
nnode_t* node = netlist->top_output_nodes[i];
for (int j = 0; j < node->num_input_pins; j++) {
merge_with_inputs(node, j);
}
}

/* traverse the internals of the flat net-list */
if (strcmp(configuration.output_type.c_str(), "blif") == 0) {
Expand All @@ -240,9 +247,7 @@ void output_blif(FILE* out, netlist_t* netlist) {
/* connect all the outputs up to the last gate */
for (long i = 0; i < netlist->num_top_output_nodes; i++) {
nnode_t* node = netlist->top_output_nodes[i];

// TODO Change this to > 1 for In Outs
if (node->input_pins[0]->net->num_fanout_pins > 0) {
if (node->input_pins[0]->net->num_fanout_pins > 1) {
nnet_t* net = node->input_pins[0]->net;
warn_undriven(node, net);
for (int j = 0; j < net->num_driver_pins; j++) {
Expand Down Expand Up @@ -541,21 +546,26 @@ void define_ff(nnode_t* node, FILE* out) {
// grab the edge sensitivity of the flip flop
const char* edge_type_str = edge_type_blif_str(node);

std::string input;
std::string output;
std::string clock_driver;
char* input_driver = buffer_multi_drivers(out, node, 0);

fprintf(out, ".latch");

/* input */
print_input_single_driver(out, node, 0);
if(!input_driver)
print_input_single_driver(out, node, 0);
else {
// Use the implicit buffer we created before
fprintf(out, " %s", input_driver);
vtr::free(input_driver);
}

/* output */
print_output_pin(out, node);

/* sensitivity */
fprintf(out, " %s", edge_type_str);

// TODO Should clocks support mutliple drivers?
/* clock */
print_input_single_driver(out, node, 1);

Expand Down
Loading