Skip to content

Commit 31f617a

Browse files
replace raw pointers with std::vector for seg_details_x/y
1 parent 017abab commit 31f617a

File tree

3 files changed

+95
-123
lines changed

3 files changed

+95
-123
lines changed

vpr/src/route/rr_graph.cpp

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,7 @@ static void rr_graph_externals(const std::vector<t_segment_inf>& segment_inf,
598598

599599
static t_clb_to_clb_directs* alloc_and_load_clb_to_clb_directs(const std::vector<t_direct_inf>& directs, const int delayless_switch);
600600

601-
static t_seg_details* alloc_and_load_global_route_seg_details(const int global_route_switch,
602-
int* num_seg_details = nullptr);
601+
static std::vector<t_seg_details> alloc_and_load_global_route_seg_details(int global_route_switch);
603602

604603
static std::vector<vtr::Matrix<int>> alloc_and_load_actual_fc(const std::vector<t_physical_tile_type>& types,
605604
const int max_pins,
@@ -1119,20 +1118,18 @@ static void build_rr_graph(const t_graph_type graph_type,
11191118
device_ctx.rr_graph_builder.add_rr_segment(segment_inf[iseg]);
11201119
}
11211120

1122-
int num_seg_details_x = 0;
1123-
int num_seg_details_y = 0;
11241121

1125-
t_seg_details* seg_details_x = nullptr;
1126-
t_seg_details* seg_details_y = nullptr;
1122+
std::vector<t_seg_details> seg_details_x;
1123+
std::vector<t_seg_details> seg_details_y;
11271124

11281125
t_unified_to_parallel_seg_index segment_index_map;
11291126
std::vector<t_segment_inf> segment_inf_x = get_parallel_segs(segment_inf, segment_index_map, X_AXIS);
11301127
std::vector<t_segment_inf> segment_inf_y = get_parallel_segs(segment_inf, segment_index_map, Y_AXIS);
11311128

11321129
if (is_global_graph) {
11331130
/* Sets up a single unit length segment type for global routing. */
1134-
seg_details_x = alloc_and_load_global_route_seg_details(global_route_switch, &num_seg_details_x);
1135-
seg_details_y = alloc_and_load_global_route_seg_details(global_route_switch, &num_seg_details_y);
1131+
seg_details_x = alloc_and_load_global_route_seg_details(global_route_switch);
1132+
seg_details_y = alloc_and_load_global_route_seg_details(global_route_switch);
11361133

11371134
} else {
11381135
/* Setup segments including distributing tracks and staggering.
@@ -1147,13 +1144,11 @@ static void build_rr_graph(const t_graph_type graph_type,
11471144
/*Get x & y segments separately*/
11481145
seg_details_x = alloc_and_load_seg_details(&max_chan_width_x,
11491146
max_dim, segment_inf_x,
1150-
use_full_seg_groups, directionality,
1151-
&num_seg_details_x);
1147+
use_full_seg_groups, directionality);
11521148

11531149
seg_details_y = alloc_and_load_seg_details(&max_chan_width_y,
11541150
max_dim, segment_inf_y,
1155-
use_full_seg_groups, directionality,
1156-
&num_seg_details_y);
1151+
use_full_seg_groups, directionality);
11571152

11581153
if (nodes_per_chan.x_max != max_chan_width_x || nodes_per_chan.y_max != max_chan_width_y) {
11591154
nodes_per_chan.x_max = max_chan_width_x;
@@ -1182,8 +1177,7 @@ static void build_rr_graph(const t_graph_type graph_type,
11821177
t_chan_details chan_details_x;
11831178
t_chan_details chan_details_y;
11841179

1185-
alloc_and_load_chan_details(grid, &nodes_per_chan,
1186-
num_seg_details_x, num_seg_details_y,
1180+
alloc_and_load_chan_details(grid, nodes_per_chan,
11871181
seg_details_x, seg_details_y,
11881182
chan_details_x, chan_details_y);
11891183

@@ -1559,12 +1553,6 @@ static void build_rr_graph(const t_graph_type graph_type,
15591553
graph_type,
15601554
is_flat);
15611555

1562-
/* Free all temp structs */
1563-
delete[] seg_details_x;
1564-
delete[] seg_details_y;
1565-
1566-
seg_details_x = nullptr;
1567-
seg_details_y = nullptr;
15681556
if (!chan_details_x.empty() || !chan_details_y.empty()) {
15691557
free_chan_details(chan_details_x, chan_details_y);
15701558
}
@@ -1992,33 +1980,30 @@ static std::vector<std::vector<bool>> alloc_and_load_perturb_ipins(const int L_n
19921980
return result;
19931981
}
19941982

1995-
static t_seg_details* alloc_and_load_global_route_seg_details(const int global_route_switch,
1996-
int* num_seg_details) {
1997-
t_seg_details* seg_details = new t_seg_details[1];
1998-
1999-
seg_details->index = 0;
2000-
seg_details->abs_index = 0;
2001-
seg_details->length = 1;
2002-
seg_details->arch_wire_switch = global_route_switch;
2003-
seg_details->arch_opin_switch = global_route_switch;
2004-
seg_details->longline = false;
2005-
seg_details->direction = Direction::BIDIR;
2006-
seg_details->Cmetal = 0.0;
2007-
seg_details->Rmetal = 0.0;
2008-
seg_details->start = 1;
2009-
seg_details->cb = std::make_unique<bool[]>(1);
2010-
seg_details->cb[0] = true;
2011-
seg_details->sb = std::make_unique<bool[]>(2);
2012-
seg_details->sb[0] = true;
2013-
seg_details->sb[1] = true;
2014-
seg_details->group_size = 1;
2015-
seg_details->group_start = 0;
2016-
seg_details->seg_start = -1;
2017-
seg_details->seg_end = -1;
2018-
2019-
if (num_seg_details) {
2020-
*num_seg_details = 1;
2021-
}
1983+
static std::vector<t_seg_details> alloc_and_load_global_route_seg_details(int global_route_switch) {
1984+
std::vector<t_seg_details> seg_details(1);
1985+
1986+
seg_details[0].index = 0;
1987+
seg_details[0].abs_index = 0;
1988+
seg_details[0].length = 1;
1989+
seg_details[0].arch_wire_switch = global_route_switch;
1990+
seg_details[0].arch_opin_switch = global_route_switch;
1991+
seg_details[0].longline = false;
1992+
seg_details[0].direction = Direction::BIDIR;
1993+
seg_details[0].Cmetal = 0.0;
1994+
seg_details[0].Rmetal = 0.0;
1995+
seg_details[0].start = 1;
1996+
seg_details[0].cb = std::make_unique<bool[]>(1);
1997+
seg_details[0].cb[0] = true;
1998+
seg_details[0].sb = std::make_unique<bool[]>(2);
1999+
seg_details[0].sb[0] = true;
2000+
seg_details[0].sb[1] = true;
2001+
seg_details[0].group_size = 1;
2002+
seg_details[0].group_start = 0;
2003+
seg_details[0].seg_start = -1;
2004+
seg_details[0].seg_end = -1;
2005+
2006+
VTR_ASSERT_DEBUG(seg_details.size() == 1);
20222007
return seg_details;
20232008
}
20242009

vpr/src/route/rr_graph2.cpp

Lines changed: 47 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,11 @@ std::unique_ptr<int[]> get_ordered_seg_track_counts(const std::vector<t_segment_
386386
return ordered_seg_track_counts;
387387
}
388388

389-
t_seg_details* alloc_and_load_seg_details(int* max_chan_width,
390-
const int max_len,
391-
const std::vector<t_segment_inf>& segment_inf,
392-
const bool use_full_seg_groups,
393-
const enum e_directionality directionality,
394-
int* num_seg_details) {
389+
std::vector<t_seg_details> alloc_and_load_seg_details(int* max_chan_width,
390+
int max_len,
391+
const std::vector<t_segment_inf>& segment_inf,
392+
bool use_full_seg_groups,
393+
enum e_directionality directionality) {
395394
/* Allocates and loads the seg_details data structure. Max_len gives the *
396395
* maximum length of a segment (dimension of array). The code below tries *
397396
* to: *
@@ -401,14 +400,9 @@ t_seg_details* alloc_and_load_seg_details(int* max_chan_width,
401400
* (3) stagger the connection and switch boxes on different long lines, *
402401
* as they will not be staggered by different segment start points. */
403402

404-
int cur_track, ntracks, itrack, length, j, index;
405-
int fac, num_sets, tmp;
406-
int arch_wire_switch, arch_opin_switch, arch_wire_switch_dec, arch_opin_switch_dec;
407-
int arch_opin_between_dice_switch;
408-
int group_start, first_track;
409-
std::unique_ptr<int[]> sets_per_seg_type;
410-
t_seg_details* seg_details = nullptr;
411-
bool longline;
403+
int cur_track;
404+
int fac;
405+
std::vector<t_seg_details> seg_details;
412406

413407
/* Unidir tracks are assigned in pairs, and bidir tracks individually */
414408
if (directionality == BI_DIRECTIONAL) {
@@ -423,46 +417,46 @@ t_seg_details* alloc_and_load_seg_details(int* max_chan_width,
423417
}
424418

425419
/* Map segment type fractions and groupings to counts of tracks */
426-
sets_per_seg_type = get_seg_track_counts((*max_chan_width / fac),
427-
segment_inf, use_full_seg_groups);
420+
std::unique_ptr<int[]> sets_per_seg_type = get_seg_track_counts((*max_chan_width / fac),
421+
segment_inf, use_full_seg_groups);
428422

429423
/* Count the number tracks actually assigned. */
430-
tmp = 0;
424+
int tmp = 0;
431425
for (size_t i = 0; i < segment_inf.size(); ++i) {
432426
tmp += sets_per_seg_type[i] * fac;
433427
}
434428
VTR_ASSERT(use_full_seg_groups || (tmp == *max_chan_width));
435429
*max_chan_width = tmp;
436430

437-
seg_details = new t_seg_details[*max_chan_width];
431+
seg_details.resize(*max_chan_width);
438432

439433
/* Setup the seg_details data */
440434
cur_track = 0;
441435
for (size_t i = 0; i < segment_inf.size(); ++i) {
442-
first_track = cur_track;
436+
int first_track = cur_track;
443437

444-
num_sets = sets_per_seg_type[i];
445-
ntracks = fac * num_sets;
438+
int num_sets = sets_per_seg_type[i];
439+
int ntracks = fac * num_sets;
446440
if (ntracks < 1) {
447441
continue;
448442
}
449443
/* Avoid divide by 0 if ntracks */
450-
longline = segment_inf[i].longline;
451-
length = segment_inf[i].length;
444+
bool longline = segment_inf[i].longline;
445+
int length = segment_inf[i].length;
452446
if (longline) {
453447
length = max_len;
454448
}
455449

456-
arch_wire_switch = segment_inf[i].arch_wire_switch;
457-
arch_opin_switch = segment_inf[i].arch_opin_switch;
458-
arch_wire_switch_dec = segment_inf[i].arch_wire_switch_dec;
459-
arch_opin_switch_dec = segment_inf[i].arch_opin_switch_dec;
460-
arch_opin_between_dice_switch = segment_inf[i].arch_opin_between_dice_switch;
450+
int arch_wire_switch = segment_inf[i].arch_wire_switch;
451+
int arch_opin_switch = segment_inf[i].arch_opin_switch;
452+
int arch_wire_switch_dec = segment_inf[i].arch_wire_switch_dec;
453+
int arch_opin_switch_dec = segment_inf[i].arch_opin_switch_dec;
454+
int arch_opin_between_dice_switch = segment_inf[i].arch_opin_between_dice_switch;
461455
VTR_ASSERT((arch_wire_switch == arch_opin_switch && arch_wire_switch_dec == arch_opin_switch_dec) || (directionality != UNI_DIRECTIONAL));
462456

463457
/* Set up the tracks of same type */
464-
group_start = 0;
465-
for (itrack = 0; itrack < ntracks; itrack++) {
458+
int group_start = 0;
459+
for (int itrack = 0; itrack < ntracks; itrack++) {
466460
/* set the name of the segment type this track belongs to */
467461
seg_details[cur_track].type_name = segment_inf[i].name;
468462

@@ -498,21 +492,21 @@ t_seg_details* alloc_and_load_seg_details(int* max_chan_width,
498492
* since this is a property of a detailed route. */
499493
seg_details[cur_track].cb = std::make_unique<bool[]>(length);
500494
seg_details[cur_track].sb = std::make_unique<bool[]>(length + 1);
501-
for (j = 0; j < length; ++j) {
495+
for (int j = 0; j < length; ++j) {
502496
if (seg_details[cur_track].longline) {
503497
seg_details[cur_track].cb[j] = true;
504498
} else {
505499
/* Use the segment's pattern. */
506-
index = j % segment_inf[i].cb.size();
500+
int index = j % segment_inf[i].cb.size();
507501
seg_details[cur_track].cb[j] = segment_inf[i].cb[index];
508502
}
509503
}
510-
for (j = 0; j < (length + 1); ++j) {
504+
for (int j = 0; j < (length + 1); ++j) {
511505
if (seg_details[cur_track].longline) {
512506
seg_details[cur_track].sb[j] = true;
513507
} else {
514508
/* Use the segment's pattern. */
515-
index = j % segment_inf[i].sb.size();
509+
int index = j % segment_inf[i].sb.size();
516510
seg_details[cur_track].sb[j] = segment_inf[i].sb[index];
517511
}
518512
}
@@ -549,9 +543,7 @@ t_seg_details* alloc_and_load_seg_details(int* max_chan_width,
549543
}
550544
} /* End for each segment type. */
551545

552-
if (num_seg_details) {
553-
*num_seg_details = cur_track;
554-
}
546+
VTR_ASSERT_DEBUG(seg_details.size() == cur_track);
555547
return seg_details;
556548
}
557549

@@ -560,32 +552,28 @@ t_seg_details* alloc_and_load_seg_details(int* max_chan_width,
560552
* (ie. channel segments) for each horizontal and vertical channel. */
561553

562554
void alloc_and_load_chan_details(const DeviceGrid& grid,
563-
const t_chan_width* nodes_per_chan,
564-
const int num_seg_details_x,
565-
const int num_seg_details_y,
566-
const t_seg_details* seg_details_x,
567-
const t_seg_details* seg_details_y,
555+
const t_chan_width& nodes_per_chan,
556+
const std::vector<t_seg_details>& seg_details_x,
557+
const std::vector<t_seg_details>& seg_details_y,
568558
t_chan_details& chan_details_x,
569559
t_chan_details& chan_details_y) {
570-
chan_details_x = init_chan_details(grid, nodes_per_chan,
571-
num_seg_details_x, seg_details_x, X_AXIS);
572-
chan_details_y = init_chan_details(grid, nodes_per_chan,
573-
num_seg_details_y, seg_details_y, Y_AXIS);
560+
chan_details_x = init_chan_details(grid, nodes_per_chan, seg_details_x, X_AXIS);
561+
chan_details_y = init_chan_details(grid, nodes_per_chan, seg_details_y, Y_AXIS);
574562

575563
/* Adjust segment start/end based on obstructed channels, if any */
576564
adjust_chan_details(grid, nodes_per_chan,
577565
chan_details_x, chan_details_y);
578566
}
579567

580568
t_chan_details init_chan_details(const DeviceGrid& grid,
581-
const t_chan_width* nodes_per_chan,
582-
const int num_seg_details,
583-
const t_seg_details* seg_details,
584-
const enum e_parallel_axis seg_parallel_axis) {
569+
const t_chan_width& nodes_per_chan,
570+
const std::vector<t_seg_details>& seg_details,
571+
enum e_parallel_axis seg_parallel_axis) {
572+
const int num_seg_details = (int)seg_details.size();
585573
if (seg_parallel_axis == X_AXIS) {
586-
VTR_ASSERT(num_seg_details <= nodes_per_chan->x_max);
574+
VTR_ASSERT(num_seg_details <= nodes_per_chan.x_max);
587575
} else if (seg_parallel_axis == Y_AXIS) {
588-
VTR_ASSERT(num_seg_details <= nodes_per_chan->y_max);
576+
VTR_ASSERT(num_seg_details <= nodes_per_chan.y_max);
589577
}
590578

591579
t_chan_details chan_details({grid.width(), grid.height(), size_t(num_seg_details)});
@@ -611,11 +599,11 @@ t_chan_details init_chan_details(const DeviceGrid& grid,
611599
p_seg_details[i].set_seg_end(seg_end);
612600

613601
if (seg_parallel_axis == X_AXIS) {
614-
if (i >= nodes_per_chan->x_list[y]) {
602+
if (i >= nodes_per_chan.x_list[y]) {
615603
p_seg_details[i].set_length(0);
616604
}
617605
} else if (seg_parallel_axis == Y_AXIS) {
618-
if (i >= nodes_per_chan->y_list[x]) {
606+
if (i >= nodes_per_chan.y_list[x]) {
619607
p_seg_details[i].set_length(0);
620608
}
621609
}
@@ -626,7 +614,7 @@ t_chan_details init_chan_details(const DeviceGrid& grid,
626614
}
627615

628616
void adjust_chan_details(const DeviceGrid& grid,
629-
const t_chan_width* nodes_per_chan,
617+
const t_chan_width& nodes_per_chan,
630618
t_chan_details& chan_details_x,
631619
t_chan_details& chan_details_y) {
632620
for (size_t y = 0; y <= grid.height() - 2; ++y) { //-2 for no perim channels
@@ -657,18 +645,18 @@ void adjust_chan_details(const DeviceGrid& grid,
657645
void adjust_seg_details(const int x,
658646
const int y,
659647
const DeviceGrid& grid,
660-
const t_chan_width* nodes_per_chan,
648+
const t_chan_width& nodes_per_chan,
661649
t_chan_details& chan_details,
662650
const enum e_parallel_axis seg_parallel_axis) {
663651
int seg_index = (seg_parallel_axis == X_AXIS ? x : y);
664652
int max_chan_width = 0;
665653
if (seg_parallel_axis == X_AXIS) {
666-
max_chan_width = nodes_per_chan->x_max;
654+
max_chan_width = nodes_per_chan.x_max;
667655
} else if (seg_parallel_axis == Y_AXIS) {
668-
max_chan_width = nodes_per_chan->y_max;
656+
max_chan_width = nodes_per_chan.y_max;
669657
} else {
670658
VTR_ASSERT(seg_parallel_axis == BOTH_AXIS);
671-
max_chan_width = nodes_per_chan->max;
659+
max_chan_width = nodes_per_chan.max;
672660
}
673661

674662
for (int track = 0; track < max_chan_width; ++track) {

0 commit comments

Comments
 (0)