Skip to content

Commit b178b8c

Browse files
authored
Merge pull request #69 from antmicro/fix-fasm-lut-issue
fasm.cpp: return from visit if pb is `open`
2 parents 2e7e9ef + 37eee2c commit b178b8c

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

utils/fasm/src/fasm.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static std::string handle_fasm_prefix(const t_metadata_dict *meta,
136136
return fasm_prefix.at(pb_graph_node->placement_index) + ".";
137137
}
138138

139-
std::string FasmWriterVisitor::build_clb_prefix(const t_pb *pb, const t_pb_graph_node* pb_graph_node) const {
139+
std::string FasmWriterVisitor::build_clb_prefix(const t_pb *pb, const t_pb_graph_node* pb_graph_node, bool* is_parent_pb_null) const {
140140
std::string clb_prefix = "";
141141

142142
const t_pb *pb_for_graph_node = nullptr;
@@ -146,22 +146,24 @@ std::string FasmWriterVisitor::build_clb_prefix(const t_pb *pb, const t_pb_graph
146146
if(root_clb_ != pb_graph_node && pb_graph_node->parent_pb_graph_node != root_clb_) {
147147
VTR_ASSERT(pb_graph_node->parent_pb_graph_node != nullptr);
148148
if(pb != nullptr) {
149-
while(pb_for_graph_node == nullptr) {
150-
pb_for_graph_node = pb->find_pb(pb_graph_node);
151-
if(pb_for_graph_node == nullptr) {
152-
if(pb->parent_pb == nullptr) {
153-
break;
154-
}
155-
pb = pb->parent_pb;
156-
}
157-
}
149+
while(pb_for_graph_node == nullptr) {
150+
pb_for_graph_node = pb->find_pb(pb_graph_node);
158151

159-
if(pb_for_graph_node != nullptr) {
160-
mode_index = pb_for_graph_node->mode;
152+
if(pb_for_graph_node == nullptr) {
153+
if(pb->parent_pb == nullptr) {
154+
*is_parent_pb_null = true;
155+
break;
156+
}
157+
pb = pb->parent_pb;
161158
}
159+
}
160+
161+
if(pb_for_graph_node != nullptr) {
162+
mode_index = pb_for_graph_node->mode;
163+
}
162164
}
163165

164-
clb_prefix = build_clb_prefix(pb, pb_graph_node->parent_pb_graph_node);
166+
clb_prefix = build_clb_prefix(pb, pb_graph_node->parent_pb_graph_node, is_parent_pb_null);
165167
}
166168

167169
const auto *pb_type = pb_graph_node->pb_type;
@@ -172,9 +174,9 @@ std::string FasmWriterVisitor::build_clb_prefix(const t_pb *pb, const t_pb_graph
172174
VTR_ASSERT(mode_index < pb_type->num_modes);
173175

174176
clb_prefix += handle_fasm_prefix(&pb_type->modes[mode_index].meta,
175-
pb_graph_node, pb_type);
177+
pb_graph_node, pb_type);
176178
} else {
177-
VTR_ASSERT(mode_index == 0);
179+
VTR_ASSERT(mode_index == 0);
178180
}
179181

180182
return clb_prefix;
@@ -220,7 +222,13 @@ void FasmWriterVisitor::visit_all_impl(const t_pb_routes &pb_routes, const t_pb*
220222

221223
const t_pb_graph_node *pb_graph_node = pb->pb_graph_node;
222224

223-
clb_prefix_ = build_clb_prefix(pb, pb_graph_node);
225+
// Check if this PB is `open` and has to be skipped
226+
bool is_parent_pb_null = false;
227+
std::string clb_prefix = build_clb_prefix(pb, pb_graph_node, &is_parent_pb_null);
228+
if (is_parent_pb_null == true) {
229+
return;
230+
}
231+
clb_prefix_ = clb_prefix;
224232

225233
t_pb_type *pb_type = pb_graph_node->pb_type;
226234
auto *mode = &pb_type->modes[pb->mode];
@@ -233,7 +241,7 @@ void FasmWriterVisitor::visit_all_impl(const t_pb_routes &pb_routes, const t_pb*
233241
if(mode != nullptr && std::string(mode->name) == "wire") {
234242
auto io_pin = is_node_used(pb_routes, pb_graph_node);
235243
if(io_pin != nullptr) {
236-
const auto& route = pb_routes.at(io_pin->pin_count_in_cluster);
244+
const auto& route = pb_routes.at(io_pin->pin_count_in_cluster);
237245
const int num_inputs = *route.pb_graph_pin->parent_node->num_input_pins;
238246
const auto *lut_definition = find_lut(route.pb_graph_pin->parent_node);
239247
VTR_ASSERT(lut_definition->num_inputs == num_inputs);

utils/fasm/src/fasm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class FasmWriterVisitor : public NetlistVisitor {
7373
void output_fasm_mux(std::string fasm_mux, t_interconnect *interconnect, t_pb_graph_pin *mux_input_pin);
7474
void walk_routing();
7575
void walk_route_tree(const t_rt_node *root);
76-
std::string build_clb_prefix(const t_pb *pb, const t_pb_graph_node* pb_graph_node) const;
76+
std::string build_clb_prefix(const t_pb *pb, const t_pb_graph_node* pb_graph_node, bool* is_parent_pb_null) const;
7777
const LutOutputDefinition* find_lut(const t_pb_graph_node* pb_graph_node);
7878
void check_for_param(const t_pb *atom);
7979

0 commit comments

Comments
 (0)