Skip to content

Commit 79321ff

Browse files
Merge pull request #3101 from AlexandreSinger/feature-libarchfpga-array-cleanup
[Infra] Converted Pin to Pin Annotations into Vector
2 parents 98c8a0f + 5ee9184 commit 79321ff

File tree

8 files changed

+138
-164
lines changed

8 files changed

+138
-164
lines changed

libs/libarchfpga/src/arch_check.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,18 @@ bool check_leaf_pb_model_timing_consistency(const t_pb_type* pb_type, const t_ar
159159
//Check from the pb_type's delay annotations match the model
160160
//
161161
// This ensures that the pb_types' delay annotations are consistent with the model
162-
for (int i = 0; i < pb_type->num_annotations; ++i) {
163-
const t_pin_to_pin_annotation* annot = &pb_type->annotations[i];
164-
165-
if (annot->type == E_ANNOT_PIN_TO_PIN_DELAY) {
162+
for (const t_pin_to_pin_annotation& annotation : pb_type->annotations) {
163+
if (annotation.type == E_ANNOT_PIN_TO_PIN_DELAY) {
166164
//Check that any combinational delays specified match the 'combinational_sinks_ports' in the model
167165

168-
if (annot->clock) {
166+
if (annotation.clock) {
169167
//Sequential annotation, check that the clock on the specified port matches the model
170168

171169
//Annotations always put the pin in the input_pins field
172-
VTR_ASSERT(annot->input_pins);
173-
for (const std::string& input_pin : vtr::split(annot->input_pins)) {
170+
VTR_ASSERT(annotation.input_pins);
171+
for (const std::string& input_pin : vtr::split(annotation.input_pins)) {
174172
InstPort annot_port(input_pin);
175-
for (const std::string& clock : vtr::split(annot->clock)) {
173+
for (const std::string& clock : vtr::split(annotation.clock)) {
176174
InstPort annot_clock(clock);
177175

178176
//Find the model port
@@ -187,34 +185,34 @@ bool check_leaf_pb_model_timing_consistency(const t_pb_type* pb_type, const t_ar
187185
if (model_port != nullptr) break;
188186
}
189187
if (model_port == nullptr) {
190-
archfpga_throw(get_arch_file_name(), annot->line_num,
188+
archfpga_throw(get_arch_file_name(), annotation.line_num,
191189
"Failed to find port '%s' on '%s' for sequential delay annotation",
192190
annot_port.port_name().c_str(), annot_port.instance_name().c_str());
193191
}
194192

195193
//Check that the clock matches the model definition
196194
std::string model_clock = model_port->clock;
197195
if (model_clock.empty()) {
198-
archfpga_throw(get_arch_file_name(), annot->line_num,
196+
archfpga_throw(get_arch_file_name(), annotation.line_num,
199197
"<pb_type> timing-annotation/<model> mismatch on port '%s' of model '%s', model specifies"
200198
" no clock but timing annotation specifies '%s'",
201199
annot_port.port_name().c_str(), model.name, annot_clock.port_name().c_str());
202200
}
203201
if (model_port->clock != annot_clock.port_name()) {
204-
archfpga_throw(get_arch_file_name(), annot->line_num,
202+
archfpga_throw(get_arch_file_name(), annotation.line_num,
205203
"<pb_type> timing-annotation/<model> mismatch on port '%s' of model '%s', model specifies"
206204
" clock as '%s' but timing annotation specifies '%s'",
207205
annot_port.port_name().c_str(), model.name, model_clock.c_str(), annot_clock.port_name().c_str());
208206
}
209207
}
210208
}
211209

212-
} else if (annot->input_pins && annot->output_pins) {
210+
} else if (annotation.input_pins && annotation.output_pins) {
213211
//Combinational annotation
214-
VTR_ASSERT_MSG(!annot->clock, "Combinational annotations should have no clock");
215-
for (const std::string& input_pin : vtr::split(annot->input_pins)) {
212+
VTR_ASSERT_MSG(!annotation.clock, "Combinational annotations should have no clock");
213+
for (const std::string& input_pin : vtr::split(annotation.input_pins)) {
216214
InstPort annot_in(input_pin);
217-
for (const std::string& output_pin : vtr::split(annot->output_pins)) {
215+
for (const std::string& output_pin : vtr::split(annotation.output_pins)) {
218216
InstPort annot_out(output_pin);
219217

220218
//Find the input model port
@@ -227,7 +225,7 @@ bool check_leaf_pb_model_timing_consistency(const t_pb_type* pb_type, const t_ar
227225
}
228226

229227
if (model_port == nullptr) {
230-
archfpga_throw(get_arch_file_name(), annot->line_num,
228+
archfpga_throw(get_arch_file_name(), annotation.line_num,
231229
"Failed to find port '%s' on '%s' for combinational delay annotation",
232230
annot_in.port_name().c_str(), annot_in.instance_name().c_str());
233231
}
@@ -237,7 +235,7 @@ bool check_leaf_pb_model_timing_consistency(const t_pb_type* pb_type, const t_ar
237235
auto e = model_port->combinational_sink_ports.end();
238236
auto iter = std::find(b, e, annot_out.port_name());
239237
if (iter == e) {
240-
archfpga_throw(get_arch_file_name(), annot->line_num,
238+
archfpga_throw(get_arch_file_name(), annotation.line_num,
241239
"<pb_type> timing-annotation/<model> mismatch on port '%s' of model '%s', timing annotation"
242240
" specifies combinational connection to port '%s' but the connection does not exist in the model",
243241
model_port->name, model.name, annot_out.port_name().c_str());
@@ -276,8 +274,8 @@ bool check_leaf_pb_model_timing_consistency(const t_pb_type* pb_type, const t_ar
276274

277275
if (model_port->dir == IN_PORT) {
278276
//Sequential inputs must have a T_setup or T_hold
279-
if (find_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_TSETUP) == nullptr
280-
&& find_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_THOLD) == nullptr) {
277+
if (!has_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_TSETUP)
278+
&& !has_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_THOLD)) {
281279
std::stringstream msg;
282280
msg << "<pb_type> '" << pb_type->name << "' timing-annotation/<model> mismatch on";
283281
msg << " port '" << model_port->name << "' of model '" << model.name << "',";
@@ -293,8 +291,8 @@ bool check_leaf_pb_model_timing_consistency(const t_pb_type* pb_type, const t_ar
293291

294292
if (!model_port->combinational_sink_ports.empty()) {
295293
//Sequential input with internal combinational connectsion it must also have T_clock_to_Q
296-
if (find_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_CLOCK_TO_Q_MAX) == nullptr
297-
&& find_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_CLOCK_TO_Q_MIN) == nullptr) {
294+
if (!has_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_CLOCK_TO_Q_MAX)
295+
&& !has_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_CLOCK_TO_Q_MIN)) {
298296
std::stringstream msg;
299297
msg << "<pb_type> '" << pb_type->name << "' timing-annotation/<model> mismatch on";
300298
msg << " port '" << model_port->name << "' of model '" << model.name << "',";
@@ -313,8 +311,8 @@ bool check_leaf_pb_model_timing_consistency(const t_pb_type* pb_type, const t_ar
313311
} else {
314312
VTR_ASSERT(model_port->dir == OUT_PORT);
315313
//Sequential outputs must have T_clock_to_Q
316-
if (find_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_CLOCK_TO_Q_MAX) == nullptr
317-
&& find_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_CLOCK_TO_Q_MIN) == nullptr) {
314+
if (!has_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_CLOCK_TO_Q_MAX)
315+
&& !has_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_CLOCK_TO_Q_MIN)) {
318316
std::stringstream msg;
319317
msg << "<pb_type> '" << pb_type->name << "' timing-annotation/<model> mismatch on";
320318
msg << " port '" << model_port->name << "' of model '" << model.name << "',";
@@ -330,8 +328,8 @@ bool check_leaf_pb_model_timing_consistency(const t_pb_type* pb_type, const t_ar
330328

331329
if (comb_connected_outputs.count(model_port->name)) {
332330
//Sequential output with internal combinational connectison must have T_setup/T_hold
333-
if (find_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_TSETUP) == nullptr
334-
&& find_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_THOLD) == nullptr) {
331+
if (!has_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_TSETUP)
332+
&& !has_sequential_annotation(pb_type, model_port, E_ANNOT_PIN_TO_PIN_DELAY_THOLD)) {
335333
std::stringstream msg;
336334
msg << "<pb_type> '" << pb_type->name << "' timing-annotation/<model> mismatch on";
337335
msg << " port '" << model_port->name << "' of model '" << model.name << "',";
@@ -352,7 +350,7 @@ bool check_leaf_pb_model_timing_consistency(const t_pb_type* pb_type, const t_ar
352350
//Check that combinationally connected inputs/outputs have combinational delays between them
353351
if (model_port->dir == IN_PORT) {
354352
for (const auto& sink_port : model_port->combinational_sink_ports) {
355-
if (find_combinational_annotation(pb_type, model_port->name, sink_port) == nullptr) {
353+
if (!has_combinational_annotation(pb_type, model_port->name, sink_port)) {
356354
std::stringstream msg;
357355
msg << "<pb_type> '" << pb_type->name << "' timing-annotation/<model> mismatch on";
358356
msg << " port '" << model_port->name << "' of model '" << model.name << "',";

libs/libarchfpga/src/arch_util.cpp

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <cstring>
22
#include <sstream>
33
#include <string>
4+
#include <vector>
45

56
#include "logic_types.h"
67
#include "vtr_assert.h"
@@ -318,12 +319,12 @@ static void free_pb_type(t_pb_type* pb_type) {
318319
vtr::free(pb_type->modes[i].interconnect[j].output_string);
319320
vtr::free(pb_type->modes[i].interconnect[j].name);
320321

321-
for (int k = 0; k < pb_type->modes[i].interconnect[j].num_annotations; ++k) {
322-
vtr::free(pb_type->modes[i].interconnect[j].annotations[k].clock);
323-
vtr::free(pb_type->modes[i].interconnect[j].annotations[k].input_pins);
324-
vtr::free(pb_type->modes[i].interconnect[j].annotations[k].output_pins);
322+
for (t_pin_to_pin_annotation& annotation : pb_type->modes[i].interconnect[j].annotations) {
323+
vtr::free(annotation.clock);
324+
vtr::free(annotation.input_pins);
325+
vtr::free(annotation.output_pins);
325326
}
326-
delete[] pb_type->modes[i].interconnect[j].annotations;
327+
pb_type->modes[i].interconnect[j].annotations.clear();
327328
delete pb_type->modes[i].interconnect[j].interconnect_power;
328329
}
329330
delete[] pb_type->modes[i].interconnect;
@@ -332,12 +333,12 @@ static void free_pb_type(t_pb_type* pb_type) {
332333

333334
delete[] pb_type->modes;
334335

335-
for (int i = 0; i < pb_type->num_annotations; ++i) {
336-
vtr::free(pb_type->annotations[i].input_pins);
337-
vtr::free(pb_type->annotations[i].output_pins);
338-
vtr::free(pb_type->annotations[i].clock);
336+
for (t_pin_to_pin_annotation& annotation : pb_type->annotations) {
337+
vtr::free(annotation.input_pins);
338+
vtr::free(annotation.output_pins);
339+
vtr::free(annotation.clock);
339340
}
340-
delete[] pb_type->annotations;
341+
pb_type->annotations.clear();
341342

342343
delete pb_type->pb_type_power;
343344

@@ -439,7 +440,6 @@ std::unordered_set<t_logical_block_type_ptr> get_equivalent_sites_set(t_physical
439440
void alloc_and_load_default_child_for_pb_type(t_pb_type* pb_type,
440441
char* new_name,
441442
t_pb_type* copy) {
442-
int i;
443443
char* dot;
444444

445445
VTR_ASSERT(pb_type->blif_model != nullptr);
@@ -464,7 +464,7 @@ void alloc_and_load_default_child_for_pb_type(t_pb_type* pb_type,
464464
/* Ports */
465465
copy->num_ports = pb_type->num_ports;
466466
copy->ports = new t_port[pb_type->num_ports]();
467-
for (i = 0; i < pb_type->num_ports; i++) {
467+
for (int i = 0; i < pb_type->num_ports; i++) {
468468
copy->ports[i].is_clock = pb_type->ports[i].is_clock;
469469
copy->ports[i].model_port = pb_type->ports[i].model_port;
470470
copy->ports[i].type = pb_type->ports[i].type;
@@ -488,9 +488,9 @@ void alloc_and_load_default_child_for_pb_type(t_pb_type* pb_type,
488488
}
489489
}
490490

491-
copy->annotations = new t_pin_to_pin_annotation[pb_type->num_annotations]();
492-
copy->num_annotations = pb_type->num_annotations;
493-
for (i = 0; i < copy->num_annotations; i++) {
491+
size_t num_annotations = pb_type->annotations.size();
492+
copy->annotations.resize(num_annotations);
493+
for (size_t i = 0; i < num_annotations; i++) {
494494
copy->annotations[i].clock = vtr::strdup(pb_type->annotations[i].clock);
495495
dot = strstr(pb_type->annotations[i].input_pins, ".");
496496
copy->annotations[i].input_pins = (char*)vtr::malloc(sizeof(char) * (strlen(new_name) + strlen(dot) + 1));
@@ -518,7 +518,6 @@ void ProcessLutClass(t_pb_type* lut_pb_type) {
518518
char* default_name;
519519
t_port* in_port;
520520
t_port* out_port;
521-
int i;
522521

523522
if (strcmp(lut_pb_type->name, "lut") != 0) {
524523
default_name = vtr::strdup("lut");
@@ -569,10 +568,9 @@ void ProcessLutClass(t_pb_type* lut_pb_type) {
569568
lut_pb_type->modes[0].interconnect[0].parent_mode = &lut_pb_type->modes[0];
570569
lut_pb_type->modes[0].interconnect[0].interconnect_power = new t_interconnect_power();
571570

572-
lut_pb_type->modes[0].interconnect[0].annotations = new t_pin_to_pin_annotation[lut_pb_type->num_annotations]();
573-
lut_pb_type->modes[0].interconnect[0].num_annotations = lut_pb_type->num_annotations;
574-
for (i = 0; i < lut_pb_type->modes[0].interconnect[0].num_annotations;
575-
i++) {
571+
size_t num_annotations = lut_pb_type->annotations.size();
572+
lut_pb_type->modes[0].interconnect[0].annotations.resize(num_annotations);
573+
for (size_t i = 0; i < num_annotations; i++) {
576574
lut_pb_type->modes[0].interconnect[0].annotations[i].clock = vtr::strdup(lut_pb_type->annotations[i].clock);
577575
lut_pb_type->modes[0].interconnect[0].annotations[i].input_pins = vtr::strdup(lut_pb_type->annotations[i].input_pins);
578576
lut_pb_type->modes[0].interconnect[0].annotations[i].output_pins = vtr::strdup(lut_pb_type->annotations[i].output_pins);
@@ -594,17 +592,15 @@ void ProcessLutClass(t_pb_type* lut_pb_type) {
594592
alloc_and_load_default_child_for_pb_type(lut_pb_type, default_name,
595593
lut_pb_type->modes[1].pb_type_children);
596594
/* moved annotations to child so delete old annotations */
597-
for (i = 0; i < lut_pb_type->num_annotations; i++) {
595+
for (size_t i = 0; i < num_annotations; i++) {
598596
vtr::free(lut_pb_type->annotations[i].input_pins);
599597
vtr::free(lut_pb_type->annotations[i].output_pins);
600598
vtr::free(lut_pb_type->annotations[i].clock);
601599
}
602-
lut_pb_type->num_annotations = 0;
603-
delete[] lut_pb_type->annotations;
604-
lut_pb_type->annotations = nullptr;
600+
lut_pb_type->annotations.clear();
605601
lut_pb_type->modes[1].pb_type_children[0].depth = lut_pb_type->depth + 1;
606602
lut_pb_type->modes[1].pb_type_children[0].parent_mode = &lut_pb_type->modes[1];
607-
for (i = 0; i < lut_pb_type->modes[1].pb_type_children[0].num_ports; i++) {
603+
for (int i = 0; i < lut_pb_type->modes[1].pb_type_children[0].num_ports; i++) {
608604
if (lut_pb_type->modes[1].pb_type_children[0].ports[i].type == IN_PORT) {
609605
lut_pb_type->modes[1].pb_type_children[0].ports[i].equivalent = PortEquivalence::FULL;
610606
}
@@ -1030,47 +1026,45 @@ bool pb_type_contains_blif_model(const t_pb_type* pb_type, const std::string& bl
10301026
return false;
10311027
}
10321028

1033-
const t_pin_to_pin_annotation* find_sequential_annotation(const t_pb_type* pb_type, const t_model_ports* port, enum e_pin_to_pin_delay_annotations annot_type) {
1029+
bool has_sequential_annotation(const t_pb_type* pb_type, const t_model_ports* port, enum e_pin_to_pin_delay_annotations annot_type) {
10341030
VTR_ASSERT(annot_type == E_ANNOT_PIN_TO_PIN_DELAY_TSETUP
10351031
|| annot_type == E_ANNOT_PIN_TO_PIN_DELAY_THOLD
10361032
|| annot_type == E_ANNOT_PIN_TO_PIN_DELAY_CLOCK_TO_Q_MAX
10371033
|| annot_type == E_ANNOT_PIN_TO_PIN_DELAY_CLOCK_TO_Q_MIN);
10381034

1039-
for (int iannot = 0; iannot < pb_type->num_annotations; ++iannot) {
1040-
const t_pin_to_pin_annotation* annot = &pb_type->annotations[iannot];
1041-
InstPort annot_in(annot->input_pins);
1035+
for (const t_pin_to_pin_annotation& annotation : pb_type->annotations) {
1036+
InstPort annot_in(annotation.input_pins);
10421037
if (annot_in.port_name() == port->name) {
1043-
for (const auto& [key, val] : annot->annotation_entries) {
1038+
for (const auto& [key, val] : annotation.annotation_entries) {
10441039
if (key == annot_type) {
1045-
return annot;
1040+
return true;
10461041
}
10471042
}
10481043
}
10491044
}
10501045

1051-
return nullptr;
1046+
return false;
10521047
}
10531048

1054-
const t_pin_to_pin_annotation* find_combinational_annotation(const t_pb_type* pb_type, std::string_view in_port, std::string_view out_port) {
1055-
for (int iannot = 0; iannot < pb_type->num_annotations; ++iannot) {
1056-
const t_pin_to_pin_annotation* annot = &pb_type->annotations[iannot];
1057-
for (const auto& annot_in_str : vtr::split(annot->input_pins)) {
1049+
bool has_combinational_annotation(const t_pb_type* pb_type, std::string_view in_port, std::string_view out_port) {
1050+
for (const t_pin_to_pin_annotation& annotation : pb_type->annotations) {
1051+
for (const auto& annot_in_str : vtr::split(annotation.input_pins)) {
10581052
InstPort in_pins(annot_in_str);
1059-
for (const auto& annot_out_str : vtr::split(annot->output_pins)) {
1053+
for (const auto& annot_out_str : vtr::split(annotation.output_pins)) {
10601054
InstPort out_pins(annot_out_str);
10611055
if (in_pins.port_name() == in_port && out_pins.port_name() == out_port) {
1062-
for (const auto& [key, val] : annot->annotation_entries) {
1056+
for (const auto& [key, val] : annotation.annotation_entries) {
10631057
if (key == E_ANNOT_PIN_TO_PIN_DELAY_MAX
10641058
|| key == E_ANNOT_PIN_TO_PIN_DELAY_MIN) {
1065-
return annot;
1059+
return true;
10661060
}
10671061
}
10681062
}
10691063
}
10701064
}
10711065
}
10721066

1073-
return nullptr;
1067+
return false;
10741068
}
10751069

10761070
void link_physical_logical_types(std::vector<t_physical_tile_type>& PhysicalTileTypes,

0 commit comments

Comments
 (0)