Skip to content

Commit 5b12cdf

Browse files
committed
equivalent tiles: changing Type lookup using unordered map
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent fc664ea commit 5b12cdf

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

libs/libarchfpga/src/read_xml_arch_file.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,24 @@ static void ProcessDevice(pugi::xml_node Node, t_arch *arch, t_default_fc_spec &
118118
static void ProcessTiles(pugi::xml_node Node,
119119
t_type_descriptor ** Types,
120120
int *NumTypes,
121+
std::unordered_map<std::string, t_type_descriptor *> *TypeMap,
121122
const pugiutil::loc_data& loc_data);
122123
static void ProcessTilesTags(pugi::xml_node Node,
123-
t_type_descriptor ** Types,
124-
int NumTypes,
124+
std::unordered_map<std::string, t_type_descriptor *> TypeMap,
125125
t_arch& arch,
126126
const t_default_fc_spec &arch_def_fc,
127127
const pugiutil::loc_data& loc_data);
128128
static void ProcessTileExtraModes(pugi::xml_node Node,
129129
t_type_descriptor *Type,
130-
t_type_descriptor **Types,
131-
int NumTypes,
130+
std::unordered_map<std::string, t_type_descriptor *> TypeMap,
132131
const pugiutil::loc_data& loc_data);
133132
static void ProcessTileExtraModePinMapping(pugi::xml_node Node,
134133
t_type_descriptor *Type,
135134
t_type_descriptor *EquivalentType,
136135
int imode,
137136
const pugiutil::loc_data& loc_data);
138137
static void ProcessComplexBlocks(pugi::xml_node Node,
139-
t_type_descriptor ** Types,
140-
int NumTypes,
138+
std::unordered_map<std::string, t_type_descriptor *> TypeMap,
141139
t_arch& arch,
142140
const bool timing_enabled,
143141
const pugiutil::loc_data& loc_data);
@@ -205,7 +203,7 @@ int find_switch_by_name(const t_arch& arch, std::string switch_name);
205203

206204
e_side string_to_side(std::string side_str);
207205

208-
static t_type_descriptor* get_correspondent_tile(t_type_descriptor ** Types, int NumTypes, const char * type_name);
206+
static t_type_descriptor* get_corresponding_tile(std::unordered_map<std::string, t_type_descriptor *> TypeMap, const char * type_name);
209207
static int get_pin_index_by_name(t_type_descriptor *Type, const char * port_name, int offset);
210208
/*
211209
*
@@ -291,16 +289,17 @@ void XmlReadArch(const char *ArchFile, const bool timing_enabled,
291289
}
292290

293291
/* Process tiles */
292+
std::unordered_map<std::string, t_type_descriptor *> TypeMap;
294293
Next = get_single_child(architecture, "tiles", loc_data);
295-
ProcessTiles(Next, Types, NumTypes, loc_data);
294+
ProcessTiles(Next, Types, NumTypes, &TypeMap, loc_data);
296295

297296
/* Process pb_types */
298297
Next = get_single_child(architecture, "complexblocklist", loc_data);
299-
ProcessComplexBlocks(Next, Types, *NumTypes, *arch, timing_enabled, loc_data);
298+
ProcessComplexBlocks(Next, TypeMap, *arch, timing_enabled, loc_data);
300299

301300
/* Process tile tags that after pb_type have been parsed */
302301
Next = get_single_child(architecture, "tiles", loc_data);
303-
ProcessTilesTags(Next, Types, *NumTypes, *arch, arch_def_fc, loc_data);
302+
ProcessTilesTags(Next, TypeMap, *arch, arch_def_fc, loc_data);
304303

305304
/* Process directs */
306305
Next = get_single_child(architecture, "directlist", loc_data, OPTIONAL);
@@ -2702,6 +2701,7 @@ static void ProcessTileProps(pugi::xml_node Node, t_type_descriptor * Type, cons
27022701
static void ProcessTiles(pugi::xml_node Node,
27032702
t_type_descriptor ** Types,
27042703
int *NumTypes,
2704+
std::unordered_map<std::string, t_type_descriptor *> *TypeMap,
27052705
const pugiutil::loc_data& loc_data) {
27062706
pugi::xml_node CurType;
27072707
pugi::xml_node Cur;
@@ -2745,6 +2745,8 @@ static void ProcessTiles(pugi::xml_node Node,
27452745

27462746
Type->index = i;
27472747

2748+
TypeMap->insert(std::make_pair(Type->name, Type));
2749+
27482750
/* Type fully read */
27492751
++i;
27502752

@@ -2757,8 +2759,7 @@ static void ProcessTiles(pugi::xml_node Node,
27572759

27582760
// This step has to be performed after the root pb_type has been parsed
27592761
static void ProcessTilesTags(pugi::xml_node Node,
2760-
t_type_descriptor ** Types,
2761-
int NumTypes,
2762+
std::unordered_map<std::string, t_type_descriptor *> TypeMap,
27622763
t_arch& arch,
27632764
const t_default_fc_spec &arch_def_fc,
27642765
const pugiutil::loc_data& loc_data) {
@@ -2774,10 +2775,10 @@ static void ProcessTilesTags(pugi::xml_node Node,
27742775
const char * NameProp = get_attribute(CurType, "name", loc_data).value();
27752776

27762777
/* Alias to current type */
2777-
Type = get_correspondent_tile(Types, NumTypes, vtr::strdup(NameProp));
2778+
Type = get_corresponding_tile(TypeMap, vtr::strdup(NameProp));
27782779
if(Type == nullptr) {
27792780
archfpga_throw(loc_data.filename_c_str(), loc_data.line(CurType),
2780-
"No tiles found correspondent to current root level pb type: '%s'.\n", Type->pb_type->name);
2781+
"No tiles found corresponding to current root level pb type: '%s'.\n", Type->pb_type->name);
27812782
}
27822783

27832784
VTR_ASSERT(Type->pb_type != nullptr);
@@ -2808,7 +2809,7 @@ static void ProcessTilesTags(pugi::xml_node Node,
28082809
/* Load possible modes (pb_types which are compatible with the current tile) */
28092810
Cur = get_single_child(CurType, "equivalent_tiles", loc_data, OPTIONAL);
28102811
if(Cur) {
2811-
ProcessTileExtraModes(Cur, Type, Types, NumTypes, loc_data);
2812+
ProcessTileExtraModes(Cur, Type, TypeMap, loc_data);
28122813
}
28132814

28142815
/* Free this node and get its next sibling node */
@@ -2836,8 +2837,7 @@ static void ProcessTilesTags(pugi::xml_node Node,
28362837
*/
28372838
static void ProcessTileExtraModes(pugi::xml_node Node,
28382839
t_type_descriptor *Type,
2839-
t_type_descriptor **Types,
2840-
int NumTypes,
2840+
std::unordered_map<std::string, t_type_descriptor *> TypeMap,
28412841
const pugiutil::loc_data& loc_data) {
28422842
pugi::xml_node CurType;
28432843

@@ -2850,10 +2850,10 @@ static void ProcessTileExtraModes(pugi::xml_node Node,
28502850
while(CurType && index < Type->num_equivalent_tiles) {
28512851
const char *equivalent_tile_name = get_attribute(CurType, "name", loc_data).value();
28522852

2853-
Type->equivalent_tiles[index] = get_correspondent_tile(Types, NumTypes, equivalent_tile_name);
2853+
Type->equivalent_tiles[index] = get_corresponding_tile(TypeMap, equivalent_tile_name);
28542854
if(Type->equivalent_tiles[index] == nullptr) {
28552855
archfpga_throw(loc_data.filename_c_str(), loc_data.line(CurType),
2856-
"No tiles found correspondent to equivalent tile name: '%s'.\n", Type->pb_type->name);
2856+
"No tiles found corresponding to equivalent tile name: '%s'.\n", Type->pb_type->name);
28572857
}
28582858

28592859
Type->equivalent_tile_pin_mapping[index] = (int *) vtr::malloc(Type->num_pins * sizeof(int));
@@ -2903,8 +2903,7 @@ static void ProcessTileExtraModePinMapping(pugi::xml_node Node,
29032903
}
29042904

29052905
static void ProcessComplexBlocks(pugi::xml_node Node,
2906-
t_type_descriptor ** Types,
2907-
int NumTypes,
2906+
std::unordered_map<std::string, t_type_descriptor *> TypeMap,
29082907
t_arch& arch,
29092908
const bool timing_enabled,
29102909
const pugiutil::loc_data& loc_data) {
@@ -2928,10 +2927,10 @@ static void ProcessComplexBlocks(pugi::xml_node Node,
29282927
}
29292928
}
29302929

2931-
Type = get_correspondent_tile(Types, NumTypes, type_name);
2930+
Type = get_corresponding_tile(TypeMap, type_name);
29322931
if(Type == nullptr) {
29332932
archfpga_throw(loc_data.filename_c_str(), loc_data.line(CurPbType),
2934-
"No tiles found correspondent to current root level pb type: '%s'.\n", type_name);
2933+
"No tiles found corresponding to current root level pb type: '%s'.\n", type_name);
29352934
}
29362935

29372936
Type->pb_type = new t_pb_type;
@@ -4407,19 +4406,16 @@ e_side string_to_side(std::string side_str) {
44074406
return side;
44084407
}
44094408

4410-
static t_type_descriptor* get_correspondent_tile(t_type_descriptor ** Types, int NumTypes, const char *type_name) {
4411-
t_type_descriptor *Type;
4409+
static t_type_descriptor* get_corresponding_tile(std::unordered_map<std::string, t_type_descriptor *> TypeMap,
4410+
const char *type_name) {
44124411

4413-
for(int i = 1 /* Skip empty tile */; i < NumTypes; i++) {
4414-
/* Alias to current type */
4415-
Type = &(*Types)[i];
4412+
auto result = TypeMap.find(type_name);
44164413

4417-
if(0 == strcmp(Type->name, type_name)){
4418-
return Type;
4419-
}
4414+
if (result == TypeMap.end()) {
4415+
return nullptr;
44204416
}
44214417

4422-
return nullptr;
4418+
return result->second;
44234419
}
44244420

44254421
static int get_pin_index_by_name(t_type_descriptor *Type, const char * port_name, int pin_index_in_port) {
@@ -4428,6 +4424,7 @@ static int get_pin_index_by_name(t_type_descriptor *Type, const char * port_name
44284424
t_pb_type *pb_type = Type->pb_type;
44294425
t_port *matched_port = nullptr;
44304426
int port_base_ipin = 0;
4427+
44314428
for (int iport = 0; iport < pb_type->num_ports; ++iport) {
44324429
t_port* port = &pb_type->ports[iport];
44334430

0 commit comments

Comments
 (0)