Skip to content

Commit f26e23c

Browse files
committed
Allow fasm_prefix on modes.
Signed-off-by: Keith Rothman <[email protected]>
1 parent e1f58d3 commit f26e23c

File tree

3 files changed

+63
-24
lines changed

3 files changed

+63
-24
lines changed

libs/libarchfpga/src/read_xml_arch_file.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,8 +1603,8 @@ static void ProcessMode(pugi::xml_node Parent, t_mode * mode,
16031603
map<string, int> pb_type_names;
16041604
pair<map<string, int>::iterator, bool> ret_pb_types;
16051605

1606-
if (0 == strcmp(Parent.name(), "pb_type")) {
1607-
/* implied mode */
1606+
bool implied_mode = 0 == strcmp(Parent.name(), "pb_type");
1607+
if (implied_mode) {
16081608
mode->name = vtr::strdup("default");
16091609
} else {
16101610
Prop = get_attribute(Parent, "name", loc_data).value();
@@ -1641,7 +1641,11 @@ static void ProcessMode(pugi::xml_node Parent, t_mode * mode,
16411641
/* Allocate power structure */
16421642
mode->mode_power = (t_mode_power*) vtr::calloc(1, sizeof(t_mode_power));
16431643

1644-
mode->meta = ProcessMetadata(Parent, loc_data);
1644+
if(!implied_mode) {
1645+
// Implied mode metadata is attached to the pb_type, rather than
1646+
// the t_mode object.
1647+
mode->meta = ProcessMetadata(Parent, loc_data);
1648+
}
16451649

16461650
/* Clear STL map used for duplicate checks */
16471651
pb_type_names.clear();

utils/fasm/src/fasm.cpp

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,41 +103,75 @@ void FasmWriterVisitor::check_interconnect(const t_pb_routes &pb_route, int inod
103103
}
104104
}
105105

106-
std::string FasmWriterVisitor::build_clb_prefix(const t_pb_graph_node* pb_graph_node) const {
107-
std::string clb_prefix = "";
108-
109-
if(root_clb_ != pb_graph_node && pb_graph_node->parent_pb_graph_node != root_clb_) {
110-
VTR_ASSERT(pb_graph_node->parent_pb_graph_node != nullptr);
111-
clb_prefix = build_clb_prefix(pb_graph_node->parent_pb_graph_node);
112-
}
113-
114-
const auto *pb_type = pb_graph_node->pb_type;
115-
bool has_prefix = pb_type->meta != nullptr
116-
&& pb_type->meta->has("fasm_prefix");
117-
106+
static std::string handle_fasm_prefix(const t_metadata_dict *meta,
107+
const t_pb_graph_node *pb_graph_node, const t_pb_type *pb_type) {
108+
bool has_prefix = meta != nullptr && meta->has("fasm_prefix");
118109
if(!has_prefix) {
119-
return clb_prefix;
110+
return "";
120111
}
121112

122-
auto fasm_prefix_unsplit = pb_type->meta->get("fasm_prefix")->front().as_string();
113+
auto fasm_prefix_unsplit = meta->get("fasm_prefix")->front().as_string();
123114
auto fasm_prefix = vtr::split(fasm_prefix_unsplit, " ");
124115
VTR_ASSERT(pb_type->num_pb >= 0);
125116
if(fasm_prefix.size() != static_cast<size_t>(pb_type->num_pb)) {
126117
vpr_throw(VPR_ERROR_OTHER,
127-
__FILE__, __LINE__,
128-
"number of fasm_prefix (%s) options (%d) for block (%s) must match capacity(%d)",
129-
fasm_prefix_unsplit, fasm_prefix.size(), pb_type->name, pb_type->num_pb);
118+
__FILE__, __LINE__,
119+
"number of fasm_prefix (%s) options (%d) for block (%s) must match capacity(%d)",
120+
fasm_prefix_unsplit, fasm_prefix.size(), pb_type->name, pb_type->num_pb);
130121
}
131122

132123
if(pb_graph_node->placement_index >= pb_type->num_pb) {
133-
vpr_throw(VPR_ERROR_OTHER,
124+
vpr_throw(VPR_ERROR_OTHER,
134125
__FILE__, __LINE__,
135126
"pb_graph_node->placement_index = %d >= pb_type->num_pb = %d",
136127
fasm_prefix_unsplit.c_str(), pb_type->num_pb);
137128
}
138129

139-
return clb_prefix + fasm_prefix.at(pb_graph_node->placement_index) + ".";
130+
return fasm_prefix.at(pb_graph_node->placement_index) + ".";
131+
}
132+
133+
std::string FasmWriterVisitor::build_clb_prefix(const t_pb *pb, const t_pb_graph_node* pb_graph_node) const {
134+
std::string clb_prefix = "";
135+
136+
const t_pb *pb_for_graph_node = nullptr;
137+
138+
// If not t_pb, mode_index is always 0.
139+
int mode_index = 0;
140+
if(root_clb_ != pb_graph_node && pb_graph_node->parent_pb_graph_node != root_clb_) {
141+
VTR_ASSERT(pb_graph_node->parent_pb_graph_node != nullptr);
142+
if(pb != nullptr) {
143+
while(pb_for_graph_node == nullptr) {
144+
pb_for_graph_node = pb->find_pb(pb_graph_node);
145+
if(pb_for_graph_node == nullptr) {
146+
if(pb->parent_pb == nullptr) {
147+
break;
148+
}
149+
pb = pb->parent_pb;
150+
}
151+
}
152+
153+
if(pb_for_graph_node != nullptr) {
154+
mode_index = pb_for_graph_node->mode;
155+
}
156+
}
157+
158+
clb_prefix = build_clb_prefix(pb, pb_graph_node->parent_pb_graph_node);
159+
}
160+
161+
const auto *pb_type = pb_graph_node->pb_type;
162+
163+
clb_prefix += handle_fasm_prefix(pb_type->meta, pb_graph_node, pb_type);
164+
165+
if(pb_type->modes != nullptr) {
166+
VTR_ASSERT(mode_index < pb_type->num_modes);
167+
168+
clb_prefix += handle_fasm_prefix(pb_type->modes[mode_index].meta,
169+
pb_graph_node, pb_type);
170+
} else {
171+
VTR_ASSERT(mode_index == 0);
172+
}
140173

174+
return clb_prefix;
141175
}
142176

143177
static const t_pb_graph_pin* is_node_used(const t_pb_routes &top_pb_route, const t_pb_graph_node* pb_graph_node) {
@@ -176,7 +210,8 @@ void FasmWriterVisitor::check_features(t_metadata_dict *meta) const {
176210

177211
void FasmWriterVisitor::visit_all_impl(const t_pb_routes &pb_route, const t_pb* pb,
178212
const t_pb_graph_node* pb_graph_node) {
179-
clb_prefix_ = build_clb_prefix(pb_graph_node);
213+
clb_prefix_ = build_clb_prefix(pb, pb_graph_node);
214+
std::cerr << "CLB prefix: " << clb_prefix_ << std::endl;
180215

181216
if(pb_graph_node && pb) {
182217
t_pb_type *pb_type = pb_graph_node->pb_type;

utils/fasm/src/fasm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class FasmWriterVisitor : public NetlistVisitor {
4141
void check_for_lut(const t_pb* atom);
4242
void output_fasm_mux(std::string fasm_mux, t_interconnect *interconnect, t_pb_graph_pin *mux_input_pin);
4343
void walk_routing();
44-
std::string build_clb_prefix(const t_pb_graph_node* pb_graph_node) const;
44+
std::string build_clb_prefix(const t_pb *pb, const t_pb_graph_node* pb_graph_node) const;
4545
const LutOutputDefinition* find_lut(const t_pb_graph_node* pb_graph_node);
4646
void check_for_param(const t_pb *atom);
4747

0 commit comments

Comments
 (0)