@@ -88,26 +88,26 @@ static int vpr_to_phy_track(const int itrack,
88
88
const t_chan_seg_details* seg_details,
89
89
const enum e_directionality directionality);
90
90
91
- static int * label_wire_muxes (const int chan_num,
92
- const int seg_num,
93
- const t_chan_seg_details* seg_details,
94
- const int seg_type_index,
95
- const int max_len,
96
- const enum e_direction dir,
97
- const int max_chan_width,
98
- const bool check_cb,
99
- int * num_wire_muxes,
100
- int * num_wire_muxes_cb_restricted);
101
-
102
- static int * label_incoming_wires (const int chan_num,
103
- const int seg_num,
104
- const int sb_seg,
105
- const t_chan_seg_details* seg_details,
106
- const int max_len,
107
- const enum e_direction dir,
108
- const int max_chan_width,
109
- int * num_incoming_wires,
110
- int * num_ending_wires);
91
+ static std::unique_ptr< int []> label_wire_muxes (const int chan_num,
92
+ const int seg_num,
93
+ const t_chan_seg_details* seg_details,
94
+ const int seg_type_index,
95
+ const int max_len,
96
+ const enum e_direction dir,
97
+ const int max_chan_width,
98
+ const bool check_cb,
99
+ int * num_wire_muxes,
100
+ int * num_wire_muxes_cb_restricted);
101
+
102
+ static std::unique_ptr< int []> label_incoming_wires (const int chan_num,
103
+ const int seg_num,
104
+ const int sb_seg,
105
+ const t_chan_seg_details* seg_details,
106
+ const int max_len,
107
+ const enum e_direction dir,
108
+ const int max_chan_width,
109
+ int * num_incoming_wires,
110
+ int * num_ending_wires);
111
111
112
112
static int find_label_of_track (int * wire_mux_on_track,
113
113
int num_wire_muxes,
@@ -143,16 +143,14 @@ static bool should_apply_switch_override(int switch_override);
143
143
* no longer less than the requested number of tracks. As a final
144
144
* step, if we were closer to target before last more, undo it
145
145
* and end up with a result that uses fewer tracks than given. */
146
- int * get_seg_track_counts (const int num_sets,
147
- const std::vector<t_segment_inf>& segment_inf,
148
- const bool use_full_seg_groups) {
149
- int * result;
150
- double * demand;
146
+ std::unique_ptr<int []> get_seg_track_counts (const int num_sets,
147
+ const std::vector<t_segment_inf>& segment_inf,
148
+ const bool use_full_seg_groups) {
151
149
int imax, freq_sum, assigned, size;
152
150
double scale, max, reduce;
153
151
154
- result = ( int *) vtr::malloc ( sizeof ( int ) * segment_inf.size ());
155
- demand = ( double *) vtr::malloc ( sizeof ( double ) * segment_inf.size ());
152
+ auto result = std::make_unique< int []>( segment_inf.size ());
153
+ auto demand = std::make_unique< double []>( segment_inf.size ());
156
154
157
155
/* Scale factor so we can divide by any length
158
156
* and still use integers */
@@ -199,13 +197,6 @@ int* get_seg_track_counts(const int num_sets,
199
197
result[imax] -= size;
200
198
}
201
199
202
- /* Free temps */
203
- if (demand) {
204
- vtr::free (demand);
205
- demand = nullptr ;
206
- }
207
-
208
- /* This must be freed by caller */
209
200
return result;
210
201
}
211
202
@@ -228,7 +219,6 @@ t_seg_details* alloc_and_load_seg_details(int* max_chan_width,
228
219
int cur_track, ntracks, itrack, length, j, index;
229
220
int arch_wire_switch, arch_opin_switch, fac, num_sets, tmp;
230
221
int group_start, first_track;
231
- int * sets_per_seg_type = nullptr ;
232
222
t_seg_details* seg_details = nullptr ;
233
223
bool longline;
234
224
@@ -245,8 +235,8 @@ t_seg_details* alloc_and_load_seg_details(int* max_chan_width,
245
235
}
246
236
247
237
/* Map segment type fractions and groupings to counts of tracks */
248
- sets_per_seg_type = get_seg_track_counts ((*max_chan_width / fac),
249
- segment_inf, use_full_seg_groups);
238
+ auto sets_per_seg_type = get_seg_track_counts ((*max_chan_width / fac),
239
+ segment_inf, use_full_seg_groups);
250
240
251
241
/* Count the number tracks actually assigned. */
252
242
tmp = 0 ;
@@ -356,9 +346,6 @@ t_seg_details* alloc_and_load_seg_details(int* max_chan_width,
356
346
}
357
347
} /* End for each segment type. */
358
348
359
- /* free variables */
360
- vtr::free (sets_per_seg_type);
361
-
362
349
if (num_seg_details) {
363
350
*num_seg_details = cur_track;
364
351
}
@@ -761,8 +748,6 @@ int get_unidir_opin_connections(const int chan,
761
748
/* Gets a linked list of Fc nodes of specified seg_type_index to connect
762
749
* to in given chan seg. Fc_ofs is used for the opin staggering pattern. */
763
750
764
- int * inc_muxes = nullptr ;
765
- int * dec_muxes = nullptr ;
766
751
int num_inc_muxes, num_dec_muxes, iconn;
767
752
int inc_inode_index, dec_inode_index;
768
753
int inc_mux, dec_mux;
@@ -781,10 +766,10 @@ int get_unidir_opin_connections(const int chan,
781
766
782
767
/* Get the lists of possible muxes. */
783
768
int dummy;
784
- inc_muxes = label_wire_muxes (chan, seg, seg_details, seg_type_index, max_len,
785
- INC_DIRECTION, max_chan_width, true , &num_inc_muxes, &dummy);
786
- dec_muxes = label_wire_muxes (chan, seg, seg_details, seg_type_index, max_len,
787
- DEC_DIRECTION, max_chan_width, true , &num_dec_muxes, &dummy);
769
+ auto inc_muxes = label_wire_muxes (chan, seg, seg_details, seg_type_index, max_len,
770
+ INC_DIRECTION, max_chan_width, true , &num_inc_muxes, &dummy);
771
+ auto dec_muxes = label_wire_muxes (chan, seg, seg_details, seg_type_index, max_len,
772
+ DEC_DIRECTION, max_chan_width, true , &num_dec_muxes, &dummy);
788
773
789
774
/* Clip Fc to the number of muxes. */
790
775
if (((Fc / 2 ) > num_inc_muxes) || ((Fc / 2 ) > num_dec_muxes)) {
@@ -823,15 +808,6 @@ int get_unidir_opin_connections(const int chan,
823
808
++num_edges;
824
809
}
825
810
826
- if (inc_muxes) {
827
- vtr::free (inc_muxes);
828
- inc_muxes = nullptr ;
829
- }
830
- if (dec_muxes) {
831
- vtr::free (dec_muxes);
832
- dec_muxes = nullptr ;
833
- }
834
-
835
811
return num_edges;
836
812
}
837
813
@@ -1850,7 +1826,6 @@ static int get_unidir_track_to_chan_seg(const int from_track,
1850
1826
const int from_rr_node,
1851
1827
t_rr_edge_info_set& rr_edges_to_create) {
1852
1828
int num_labels = 0 ;
1853
- int * mux_labels = nullptr ;
1854
1829
1855
1830
/* x, y coords for get_rr_node lookups */
1856
1831
int to_x = (CHANX == to_type ? to_seg : to_chan);
@@ -1868,15 +1843,11 @@ static int get_unidir_track_to_chan_seg(const int from_track,
1868
1843
1869
1844
/* get list of muxes to which we can connect */
1870
1845
int dummy;
1871
- mux_labels = label_wire_muxes (to_chan, to_seg, seg_details, UNDEFINED, max_len,
1872
- to_dir, max_chan_width, false , &num_labels, &dummy);
1846
+ auto mux_labels = label_wire_muxes (to_chan, to_seg, seg_details, UNDEFINED, max_len,
1847
+ to_dir, max_chan_width, false , &num_labels, &dummy);
1873
1848
1874
1849
/* Can't connect if no muxes. */
1875
1850
if (num_labels < 1 ) {
1876
- if (mux_labels) {
1877
- vtr::free (mux_labels);
1878
- mux_labels = nullptr ;
1879
- }
1880
1851
return 0 ;
1881
1852
}
1882
1853
@@ -1929,10 +1900,6 @@ static int get_unidir_track_to_chan_seg(const int from_track,
1929
1900
}
1930
1901
}
1931
1902
1932
- if (mux_labels) {
1933
- vtr::free (mux_labels);
1934
- mux_labels = nullptr ;
1935
- }
1936
1903
return count;
1937
1904
}
1938
1905
@@ -2159,8 +2126,8 @@ void load_sblock_pattern_lookup(const int i,
2159
2126
2160
2127
/* SB's range from (0, 0) to (grid.width() - 2, grid.height() - 2) */
2161
2128
/* First find all four sides' incoming wires */
2162
- int * wire_mux_on_track[4 ];
2163
- int * incoming_wire_label[4 ];
2129
+ std::unique_ptr< int []> wire_mux_on_track[4 ];
2130
+ std::unique_ptr< int []> incoming_wire_label[4 ];
2164
2131
int num_incoming_wires[4 ];
2165
2132
int num_ending_wires[4 ];
2166
2133
int num_wire_muxes[4 ];
@@ -2314,7 +2281,7 @@ void load_sblock_pattern_lookup(const int i,
2314
2281
* use any pattern such as Wilton */
2315
2282
/* In the direct connect case, I know for sure the init mux is at the same track #
2316
2283
* as this ending wire, but still need to find the init mux label for Fs > 3 */
2317
- int mux = find_label_of_track (wire_mux_on_track[to_side],
2284
+ int mux = find_label_of_track (wire_mux_on_track[to_side]. get () ,
2318
2285
num_wire_muxes[to_side], itrack);
2319
2286
sblock_pattern[i][j][side_opp][to_side][itrack][0 ] = mux;
2320
2287
} else {
@@ -2331,35 +2298,26 @@ void load_sblock_pattern_lookup(const int i,
2331
2298
}
2332
2299
}
2333
2300
}
2334
-
2335
- for (e_side side : {TOP, RIGHT, BOTTOM, LEFT}) {
2336
- if (incoming_wire_label[side]) {
2337
- vtr::free (incoming_wire_label[side]);
2338
- }
2339
- if (wire_mux_on_track[side]) {
2340
- vtr::free (wire_mux_on_track[side]);
2341
- }
2342
- }
2343
2301
}
2344
2302
2345
- static int * label_wire_muxes (const int chan_num,
2346
- const int seg_num,
2347
- const t_chan_seg_details* seg_details,
2348
- const int seg_type_index,
2349
- const int max_len,
2350
- const enum e_direction dir,
2351
- const int max_chan_width,
2352
- const bool check_cb,
2353
- int * num_wire_muxes,
2354
- int * num_wire_muxes_cb_restricted) {
2303
+ static std::unique_ptr< int []> label_wire_muxes (const int chan_num,
2304
+ const int seg_num,
2305
+ const t_chan_seg_details* seg_details,
2306
+ const int seg_type_index,
2307
+ const int max_len,
2308
+ const enum e_direction dir,
2309
+ const int max_chan_width,
2310
+ const bool check_cb,
2311
+ int * num_wire_muxes,
2312
+ int * num_wire_muxes_cb_restricted) {
2355
2313
/* Labels the muxes on that side (seg_num, chan_num, direction). The returned array
2356
2314
* maps a label to the actual track #: array[0] = <the track number of the first/lowest mux>
2357
2315
* This routine orders wire muxes by their natural order, i.e. track #
2358
2316
* If seg_type_index == UNDEFINED, all segments in the channel are considered. Otherwise this routine
2359
2317
* only looks at segments that belong to the specified segment type. */
2360
2318
2361
2319
int itrack, start, end, num_labels, num_labels_restricted, pass;
2362
- int * labels = nullptr ;
2320
+ std::unique_ptr< int []> labels;
2363
2321
bool is_endpoint;
2364
2322
2365
2323
/* COUNT pass then a LOAD pass */
@@ -2368,7 +2326,7 @@ static int* label_wire_muxes(const int chan_num,
2368
2326
for (pass = 0 ; pass < 2 ; ++pass) {
2369
2327
/* Alloc the list on LOAD pass */
2370
2328
if (pass > 0 ) {
2371
- labels = ( int *) vtr::malloc ( sizeof ( int ) * num_labels);
2329
+ labels = std::make_unique< int []>( num_labels);
2372
2330
num_labels = 0 ;
2373
2331
}
2374
2332
@@ -2427,25 +2385,25 @@ static int* label_wire_muxes(const int chan_num,
2427
2385
return labels;
2428
2386
}
2429
2387
2430
- static int * label_incoming_wires (const int chan_num,
2431
- const int seg_num,
2432
- const int sb_seg,
2433
- const t_chan_seg_details* seg_details,
2434
- const int max_len,
2435
- const enum e_direction dir,
2436
- const int max_chan_width,
2437
- int * num_incoming_wires,
2438
- int * num_ending_wires) {
2388
+ static std::unique_ptr< int []> label_incoming_wires (const int chan_num,
2389
+ const int seg_num,
2390
+ const int sb_seg,
2391
+ const t_chan_seg_details* seg_details,
2392
+ const int max_len,
2393
+ const enum e_direction dir,
2394
+ const int max_chan_width,
2395
+ int * num_incoming_wires,
2396
+ int * num_ending_wires) {
2439
2397
/* Labels the incoming wires on that side (seg_num, chan_num, direction).
2440
2398
* The returned array maps a track # to a label: array[0] = <the new hash value/label for track 0>,
2441
2399
* the labels 0,1,2,.. identify consecutive incoming wires that have sblock (passing wires with sblock and ending wires) */
2442
2400
2443
2401
int itrack, start, end, i, num_passing, num_ending, pass;
2444
- int * labels;
2445
2402
bool sblock_exists, is_endpoint;
2446
2403
2447
2404
/* Alloc the list of labels for the tracks */
2448
- labels = (int *)vtr::malloc (max_chan_width * sizeof (int ));
2405
+ auto labels = std::make_unique<int []>(max_chan_width);
2406
+
2449
2407
for (i = 0 ; i < max_chan_width; ++i) {
2450
2408
labels[i] = UN_SET; /* crash hard if unset */
2451
2409
}
0 commit comments