@@ -5179,7 +5179,6 @@ static void process_vib(pugi::xml_node Vib_node, std::vector<t_physical_tile_typ
5179
5179
5180
5180
int group_num = count_children (Vib_node, " seg_group" , loc_data);
5181
5181
VTR_ASSERT (vib.get_seg_group_num () == group_num);
5182
- // vib.seg_groups.reserve(group_num);
5183
5182
pugi::xml_node Node = get_first_child (Vib_node, " seg_group" , loc_data);
5184
5183
for (int i_group = 0 ; i_group < group_num; i_group++) {
5185
5184
t_seg_group seg_group;
@@ -5418,206 +5417,164 @@ static void process_vib_block_type_locs(t_vib_grid_def& grid_def,
5418
5417
vtr::string_internment& strings,
5419
5418
pugi::xml_node layout_block_type_tag,
5420
5419
const pugiutil::loc_data& loc_data) {
5420
+ // Helper struct to define coordinate parameters
5421
+ struct CoordParams {
5422
+ std::string x_start, x_end, y_start, y_end;
5423
+ std::string x_repeat = " " , x_incr = " " , y_repeat = " " , y_incr = " " ;
5424
+
5425
+ CoordParams (const std::string& xs, const std::string& xe,
5426
+ const std::string& ys, const std::string& ye)
5427
+ : x_start(xs), x_end(xe), y_start(ys), y_end(ye) {}
5428
+
5429
+ CoordParams () = default ;
5430
+ };
5431
+
5421
5432
// Process all the block location specifications
5422
5433
for (auto loc_spec_tag : layout_block_type_tag.children ()) {
5423
5434
auto loc_type = loc_spec_tag.name ();
5424
5435
auto type_name = get_attribute (loc_spec_tag, " type" , loc_data).value ();
5425
5436
int priority = get_attribute (loc_spec_tag, " priority" , loc_data).as_int ();
5426
5437
t_metadata_dict meta = process_meta_data (strings, loc_spec_tag, loc_data);
5427
5438
5439
+ auto & loc_defs = grid_def.layers .at (die_number).loc_defs ;
5440
+
5428
5441
if (loc_type == std::string (" perimeter" )) {
5429
5442
expect_only_attributes (loc_spec_tag, {" type" , " priority" }, loc_data);
5430
5443
5431
- // The edges
5432
- t_vib_grid_loc_def left_edge (type_name, priority); // Including corners
5433
- left_edge.x .start_expr = " 0" ;
5434
- left_edge.x .end_expr = " 0" ;
5435
- left_edge.y .start_expr = " 0" ;
5436
- left_edge.y .end_expr = " H - 1" ;
5437
-
5438
- t_vib_grid_loc_def right_edge (type_name, priority); // Including corners
5439
- right_edge.x .start_expr = " W - 1" ;
5440
- right_edge.x .end_expr = " W - 1" ;
5441
- right_edge.y .start_expr = " 0" ;
5442
- right_edge.y .end_expr = " H - 1" ;
5443
-
5444
- t_vib_grid_loc_def bottom_edge (type_name, priority); // Exclucing corners
5445
- bottom_edge.x .start_expr = " 1" ;
5446
- bottom_edge.x .end_expr = " W - 2" ;
5447
- bottom_edge.y .start_expr = " 0" ;
5448
- bottom_edge.y .end_expr = " 0" ;
5449
-
5450
- t_vib_grid_loc_def top_edge (type_name, priority); // Excluding corners
5451
- top_edge.x .start_expr = " 1" ;
5452
- top_edge.x .end_expr = " W - 2" ;
5453
- top_edge.y .start_expr = " H - 1" ;
5454
- top_edge.y .end_expr = " H - 1" ;
5455
-
5456
- grid_def.layers .at (die_number).loc_defs .emplace_back (std::move (left_edge));
5457
- grid_def.layers .at (die_number).loc_defs .emplace_back (std::move (right_edge));
5458
- grid_def.layers .at (die_number).loc_defs .emplace_back (std::move (top_edge));
5459
- grid_def.layers .at (die_number).loc_defs .emplace_back (std::move (bottom_edge));
5460
-
5444
+ const std::vector<CoordParams> perimeter_edges = {
5445
+ {" 0" , " 0" , " 0" , " H - 1" }, // left (including corners)
5446
+ {" W - 1" , " W - 1" , " 0" , " H - 1" }, // right (including corners)
5447
+ {" 1" , " W - 2" , " 0" , " 0" }, // bottom (excluding corners)
5448
+ {" 1" , " W - 2" , " H - 1" , " H - 1" } // top (excluding corners)
5449
+ };
5450
+
5451
+ for (const auto & edge : perimeter_edges) {
5452
+ t_vib_grid_loc_def edge_def (type_name, priority);
5453
+ edge_def.x .start_expr = edge.x_start ;
5454
+ edge_def.x .end_expr = edge.x_end ;
5455
+ edge_def.y .start_expr = edge.y_start ;
5456
+ edge_def.y .end_expr = edge.y_end ;
5457
+ loc_defs.emplace_back (std::move (edge_def));
5458
+ }
5461
5459
} else if (loc_type == std::string (" corners" )) {
5462
5460
expect_only_attributes (loc_spec_tag, {" type" , " priority" }, loc_data);
5463
5461
5464
- // The corners
5465
- t_vib_grid_loc_def bottom_left (type_name, priority);
5466
- bottom_left.x .start_expr = " 0" ;
5467
- bottom_left.x .end_expr = " 0" ;
5468
- bottom_left.y .start_expr = " 0" ;
5469
- bottom_left.y .end_expr = " 0" ;
5470
-
5471
- t_vib_grid_loc_def top_left (type_name, priority);
5472
- top_left.x .start_expr = " 0" ;
5473
- top_left.x .end_expr = " 0" ;
5474
- top_left.y .start_expr = " H-1" ;
5475
- top_left.y .end_expr = " H-1" ;
5476
-
5477
- t_vib_grid_loc_def bottom_right (type_name, priority);
5478
- bottom_right.x .start_expr = " W-1" ;
5479
- bottom_right.x .end_expr = " W-1" ;
5480
- bottom_right.y .start_expr = " 0" ;
5481
- bottom_right.y .end_expr = " 0" ;
5482
-
5483
- t_vib_grid_loc_def top_right (type_name, priority);
5484
- top_right.x .start_expr = " W-1" ;
5485
- top_right.x .end_expr = " W-1" ;
5486
- top_right.y .start_expr = " H-1" ;
5487
- top_right.y .end_expr = " H-1" ;
5488
-
5489
- grid_def.layers .at (die_number).loc_defs .emplace_back (std::move (bottom_left));
5490
- grid_def.layers .at (die_number).loc_defs .emplace_back (std::move (top_left));
5491
- grid_def.layers .at (die_number).loc_defs .emplace_back (std::move (bottom_right));
5492
- grid_def.layers .at (die_number).loc_defs .emplace_back (std::move (top_right));
5493
-
5462
+ const std::vector<CoordParams> corner_positions = {
5463
+ {" 0" , " 0" , " 0" , " 0" }, // bottom_left
5464
+ {" 0" , " 0" , " H-1" , " H-1" }, // top_left
5465
+ {" W-1" , " W-1" , " 0" , " 0" }, // bottom_right
5466
+ {" W-1" , " W-1" , " H-1" , " H-1" } // top_right
5467
+ };
5468
+
5469
+ for (const auto & corner : corner_positions) {
5470
+ t_vib_grid_loc_def corner_def (type_name, priority);
5471
+ corner_def.x .start_expr = corner.x_start ;
5472
+ corner_def.x .end_expr = corner.x_end ;
5473
+ corner_def.y .start_expr = corner.y_start ;
5474
+ corner_def.y .end_expr = corner.y_end ;
5475
+ loc_defs.emplace_back (std::move (corner_def));
5476
+ }
5494
5477
} else if (loc_type == std::string (" fill" )) {
5495
5478
expect_only_attributes (loc_spec_tag, {" type" , " priority" }, loc_data);
5496
5479
5497
- t_vib_grid_loc_def fill (type_name, priority);
5498
- fill.x .start_expr = " 0" ;
5499
- fill.x .end_expr = " W - 1" ;
5500
- fill.y .start_expr = " 0" ;
5501
- fill.y .end_expr = " H - 1" ;
5502
-
5503
- // fill.owned_meta = std::make_unique<t_metadata_dict>(meta);
5504
- // fill.meta = fill.owned_meta.get();
5505
-
5506
- grid_def.layers .at (die_number).loc_defs .emplace_back (std::move (fill));
5507
-
5480
+ t_vib_grid_loc_def fill_def (type_name, priority);
5481
+ fill_def.x .start_expr = " 0" ;
5482
+ fill_def.x .end_expr = " W - 1" ;
5483
+ fill_def.y .start_expr = " 0" ;
5484
+ fill_def.y .end_expr = " H - 1" ;
5485
+ loc_defs.push_back (std::move (fill_def));
5508
5486
} else if (loc_type == std::string (" single" )) {
5509
5487
expect_only_attributes (loc_spec_tag, {" type" , " priority" , " x" , " y" }, loc_data);
5510
5488
5511
- t_vib_grid_loc_def single (type_name, priority);
5512
- single.x .start_expr = get_attribute (loc_spec_tag, " x" , loc_data).value ();
5513
- single.y .start_expr = get_attribute (loc_spec_tag, " y" , loc_data).value ();
5514
- single.x .end_expr = single.x .start_expr + " + w - 1" ;
5515
- single.y .end_expr = single.y .start_expr + " + h - 1" ;
5516
-
5517
- grid_def.layers .at (die_number).loc_defs .emplace_back (std::move (single));
5518
-
5489
+ const std::string x_pos = get_attribute (loc_spec_tag, " x" , loc_data).value ();
5490
+ const std::string y_pos = get_attribute (loc_spec_tag, " y" , loc_data).value ();
5491
+
5492
+ t_vib_grid_loc_def single_def (type_name, priority);
5493
+ single_def.x .start_expr = x_pos;
5494
+ single_def.x .end_expr = x_pos + " + w - 1" ;
5495
+ single_def.y .start_expr = y_pos;
5496
+ single_def.y .end_expr = y_pos + " + h - 1" ;
5497
+ loc_defs.push_back (std::move (single_def));
5519
5498
} else if (loc_type == std::string (" col" )) {
5520
5499
expect_only_attributes (loc_spec_tag, {" type" , " priority" , " startx" , " repeatx" , " starty" , " incry" }, loc_data);
5521
5500
5522
- t_vib_grid_loc_def col (type_name, priority );
5523
-
5524
- auto startx_attr = get_attribute (loc_spec_tag, " startx " , loc_data );
5525
-
5526
- col .x .start_expr = startx_attr. value () ;
5527
- col. x . end_expr = startx_attr. value () + std::string ( " + w - 1 " ); // end is inclusive so need to include block width
5528
-
5501
+ const std::string start_x = get_attribute (loc_spec_tag, " startx " , loc_data). value ( );
5502
+
5503
+ t_vib_grid_loc_def col_def (type_name, priority );
5504
+ col_def. x . start_expr = start_x;
5505
+ col_def .x .end_expr = start_x + " + w - 1 " ;
5506
+
5507
+ // Handle optional attributes
5529
5508
auto repeat_attr = get_attribute (loc_spec_tag, " repeatx" , loc_data, ReqOpt::OPTIONAL);
5530
5509
if (repeat_attr) {
5531
- col .x .repeat_expr = repeat_attr.value ();
5510
+ col_def .x .repeat_expr = repeat_attr.value ();
5532
5511
}
5533
-
5534
- auto starty_attr = get_attribute (loc_spec_tag, " starty" , loc_data, ReqOpt::OPTIONAL);
5535
- if (starty_attr ) {
5536
- col .y .start_expr = starty_attr .value ();
5512
+
5513
+ auto start_y_attr = get_attribute (loc_spec_tag, " starty" , loc_data, ReqOpt::OPTIONAL);
5514
+ if (start_y_attr ) {
5515
+ col_def .y .start_expr = start_y_attr .value ();
5537
5516
}
5538
-
5539
- auto incry_attr = get_attribute (loc_spec_tag, " incry" , loc_data, ReqOpt::OPTIONAL);
5540
- if (incry_attr ) {
5541
- col .y .incr_expr = incry_attr .value ();
5517
+
5518
+ auto incr_y_attr = get_attribute (loc_spec_tag, " incry" , loc_data, ReqOpt::OPTIONAL);
5519
+ if (incr_y_attr ) {
5520
+ col_def .y .incr_expr = incr_y_attr .value ();
5542
5521
}
5543
-
5544
- grid_def. layers . at (die_number). loc_defs .emplace_back (std::move (col ));
5522
+
5523
+ loc_defs.push_back (std::move (col_def ));
5545
5524
5546
5525
} else if (loc_type == std::string (" row" )) {
5547
5526
expect_only_attributes (loc_spec_tag, {" type" , " priority" , " starty" , " repeaty" , " startx" , " incrx" }, loc_data);
5548
5527
5549
- t_vib_grid_loc_def row (type_name, priority );
5550
-
5551
- auto starty_attr = get_attribute (loc_spec_tag, " starty " , loc_data );
5552
-
5553
- row .y .start_expr = starty_attr. value () ;
5554
- row. y . end_expr = starty_attr. value () + std::string ( " + h - 1 " ); // end is inclusive so need to include block height
5555
-
5528
+ const std::string start_y = get_attribute (loc_spec_tag, " starty " , loc_data). value ( );
5529
+
5530
+ t_vib_grid_loc_def row_def (type_name, priority );
5531
+ row_def. y . start_expr = start_y;
5532
+ row_def .y .end_expr = start_y + " + h - 1 " ;
5533
+
5534
+ // Handle optional attributes
5556
5535
auto repeat_attr = get_attribute (loc_spec_tag, " repeaty" , loc_data, ReqOpt::OPTIONAL);
5557
5536
if (repeat_attr) {
5558
- row .y .repeat_expr = repeat_attr.value ();
5537
+ row_def .y .repeat_expr = repeat_attr.value ();
5559
5538
}
5560
-
5561
- auto startx_attr = get_attribute (loc_spec_tag, " startx" , loc_data, ReqOpt::OPTIONAL);
5562
- if (startx_attr ) {
5563
- row .x .start_expr = startx_attr .value ();
5539
+
5540
+ auto start_x_attr = get_attribute (loc_spec_tag, " startx" , loc_data, ReqOpt::OPTIONAL);
5541
+ if (start_x_attr ) {
5542
+ row_def .x .start_expr = start_x_attr .value ();
5564
5543
}
5565
-
5566
- auto incrx_attr = get_attribute (loc_spec_tag, " incrx" , loc_data, ReqOpt::OPTIONAL);
5567
- if (incrx_attr ) {
5568
- row .x .incr_expr = incrx_attr .value ();
5544
+
5545
+ auto incr_x_attr = get_attribute (loc_spec_tag, " incrx" , loc_data, ReqOpt::OPTIONAL);
5546
+ if (incr_x_attr ) {
5547
+ row_def .x .incr_expr = incr_x_attr .value ();
5569
5548
}
5570
-
5571
- grid_def. layers . at (die_number). loc_defs .emplace_back (std::move (row ));
5549
+
5550
+ loc_defs.push_back (std::move (row_def ));
5572
5551
} else if (loc_type == std::string (" region" )) {
5573
5552
expect_only_attributes (loc_spec_tag,
5574
5553
{" type" , " priority" ,
5575
5554
" startx" , " endx" , " repeatx" , " incrx" ,
5576
5555
" starty" , " endy" , " repeaty" , " incry" },
5577
5556
loc_data);
5578
- t_vib_grid_loc_def region (type_name, priority);
5579
-
5580
- auto startx_attr = get_attribute (loc_spec_tag, " startx" , loc_data, ReqOpt::OPTIONAL);
5581
- if (startx_attr) {
5582
- region.x .start_expr = startx_attr.value ();
5583
- }
5584
-
5585
- auto endx_attr = get_attribute (loc_spec_tag, " endx" , loc_data, ReqOpt::OPTIONAL);
5586
- if (endx_attr) {
5587
- region.x .end_expr = endx_attr.value ();
5588
- }
5589
-
5590
- auto starty_attr = get_attribute (loc_spec_tag, " starty" , loc_data, ReqOpt::OPTIONAL);
5591
- if (starty_attr) {
5592
- region.y .start_expr = starty_attr.value ();
5593
- }
5594
-
5595
- auto endy_attr = get_attribute (loc_spec_tag, " endy" , loc_data, ReqOpt::OPTIONAL);
5596
- if (endy_attr) {
5597
- region.y .end_expr = endy_attr.value ();
5598
- }
5599
-
5600
- auto repeatx_attr = get_attribute (loc_spec_tag, " repeatx" , loc_data, ReqOpt::OPTIONAL);
5601
- if (repeatx_attr) {
5602
- region.x .repeat_expr = repeatx_attr.value ();
5603
- }
5604
-
5605
- auto repeaty_attr = get_attribute (loc_spec_tag, " repeaty" , loc_data, ReqOpt::OPTIONAL);
5606
- if (repeaty_attr) {
5607
- region.y .repeat_expr = repeaty_attr.value ();
5608
- }
5609
-
5610
- auto incrx_attr = get_attribute (loc_spec_tag, " incrx" , loc_data, ReqOpt::OPTIONAL);
5611
- if (incrx_attr) {
5612
- region.x .incr_expr = incrx_attr.value ();
5613
- }
5614
-
5615
- auto incry_attr = get_attribute (loc_spec_tag, " incry" , loc_data, ReqOpt::OPTIONAL);
5616
- if (incry_attr) {
5617
- region.y .incr_expr = incry_attr.value ();
5618
- }
5619
-
5620
- grid_def.layers .at (die_number).loc_defs .emplace_back (std::move (region));
5557
+ t_vib_grid_loc_def region_def (type_name, priority);
5558
+
5559
+ // Helper lambda to set optional attribute
5560
+ auto set_optional_attr = [&](const char * attr_name, std::string& target) {
5561
+ auto attr = get_attribute (loc_spec_tag, attr_name, loc_data, ReqOpt::OPTIONAL);
5562
+ if (attr) {
5563
+ target = attr.value ();
5564
+ }
5565
+ };
5566
+
5567
+ // Set all optional region attributes
5568
+ set_optional_attr (" startx" , region_def.x .start_expr );
5569
+ set_optional_attr (" endx" , region_def.x .end_expr );
5570
+ set_optional_attr (" repeatx" , region_def.x .repeat_expr );
5571
+ set_optional_attr (" incrx" , region_def.x .incr_expr );
5572
+ set_optional_attr (" starty" , region_def.y .start_expr );
5573
+ set_optional_attr (" endy" , region_def.y .end_expr );
5574
+ set_optional_attr (" repeaty" , region_def.y .repeat_expr );
5575
+ set_optional_attr (" incry" , region_def.y .incr_expr );
5576
+
5577
+ loc_defs.push_back (std::move (region_def));
5621
5578
} else {
5622
5579
archfpga_throw (loc_data.filename_c_str (), loc_data.line (loc_spec_tag),
5623
5580
" Unrecognized grid location specification type '%s'\n " , loc_type);
0 commit comments