diff --git a/libs/libarchfpga/src/arch_util.cpp b/libs/libarchfpga/src/arch_util.cpp index 37e63f7d96c..a8d89c91ed5 100644 --- a/libs/libarchfpga/src/arch_util.cpp +++ b/libs/libarchfpga/src/arch_util.cpp @@ -298,7 +298,7 @@ static void free_all_pb_graph_nodes(std::vector& type_desc if (type.pb_type) { if (type.pb_graph_head) { free_pb_graph(type.pb_graph_head); - vtr::free(type.pb_graph_head); + delete type.pb_graph_head; } } } @@ -316,78 +316,46 @@ static void free_pb_graph(t_pb_graph_node* pb_graph_node) { /* Free ports for pb graph node */ for (i = 0; i < pb_graph_node->num_input_ports; i++) { for (j = 0; j < pb_graph_node->num_input_pins[i]; j++) { - if (pb_graph_node->input_pins[i][j].pin_timing) - vtr::free(pb_graph_node->input_pins[i][j].pin_timing); - if (pb_graph_node->input_pins[i][j].pin_timing_del_max) - vtr::free(pb_graph_node->input_pins[i][j].pin_timing_del_max); - if (pb_graph_node->input_pins[i][j].pin_timing_del_min) - vtr::free(pb_graph_node->input_pins[i][j].pin_timing_del_min); - if (pb_graph_node->input_pins[i][j].input_edges) - vtr::free(pb_graph_node->input_pins[i][j].input_edges); - if (pb_graph_node->input_pins[i][j].output_edges) - vtr::free(pb_graph_node->input_pins[i][j].output_edges); if (pb_graph_node->input_pins[i][j].parent_pin_class) - vtr::free(pb_graph_node->input_pins[i][j].parent_pin_class); + delete[] pb_graph_node->input_pins[i][j].parent_pin_class; } delete[] pb_graph_node->input_pins[i]; } for (i = 0; i < pb_graph_node->num_output_ports; i++) { for (j = 0; j < pb_graph_node->num_output_pins[i]; j++) { - if (pb_graph_node->output_pins[i][j].pin_timing) - vtr::free(pb_graph_node->output_pins[i][j].pin_timing); - if (pb_graph_node->output_pins[i][j].pin_timing_del_max) - vtr::free(pb_graph_node->output_pins[i][j].pin_timing_del_max); - if (pb_graph_node->output_pins[i][j].pin_timing_del_min) - vtr::free(pb_graph_node->output_pins[i][j].pin_timing_del_min); - if (pb_graph_node->output_pins[i][j].input_edges) - vtr::free(pb_graph_node->output_pins[i][j].input_edges); - if (pb_graph_node->output_pins[i][j].output_edges) - vtr::free(pb_graph_node->output_pins[i][j].output_edges); if (pb_graph_node->output_pins[i][j].parent_pin_class) - vtr::free(pb_graph_node->output_pins[i][j].parent_pin_class); + delete[] pb_graph_node->output_pins[i][j].parent_pin_class; if (pb_graph_node->output_pins[i][j].list_of_connectable_input_pin_ptrs) { for (k = 0; k < pb_graph_node->pb_type->depth; k++) { - if (pb_graph_node->output_pins[i][j].list_of_connectable_input_pin_ptrs[k]) { - vtr::free(pb_graph_node->output_pins[i][j].list_of_connectable_input_pin_ptrs[k]); - } + delete[] pb_graph_node->output_pins[i][j].list_of_connectable_input_pin_ptrs[k]; } - vtr::free(pb_graph_node->output_pins[i][j].list_of_connectable_input_pin_ptrs); + delete[] pb_graph_node->output_pins[i][j].list_of_connectable_input_pin_ptrs; } if (pb_graph_node->output_pins[i][j].num_connectable_primitive_input_pins) - vtr::free(pb_graph_node->output_pins[i][j].num_connectable_primitive_input_pins); + delete[] pb_graph_node->output_pins[i][j].num_connectable_primitive_input_pins; } delete[] pb_graph_node->output_pins[i]; } for (i = 0; i < pb_graph_node->num_clock_ports; i++) { for (j = 0; j < pb_graph_node->num_clock_pins[i]; j++) { - if (pb_graph_node->clock_pins[i][j].pin_timing) - vtr::free(pb_graph_node->clock_pins[i][j].pin_timing); - if (pb_graph_node->clock_pins[i][j].pin_timing_del_max) - vtr::free(pb_graph_node->clock_pins[i][j].pin_timing_del_max); - if (pb_graph_node->clock_pins[i][j].pin_timing_del_min) - vtr::free(pb_graph_node->clock_pins[i][j].pin_timing_del_min); - if (pb_graph_node->clock_pins[i][j].input_edges) - vtr::free(pb_graph_node->clock_pins[i][j].input_edges); - if (pb_graph_node->clock_pins[i][j].output_edges) - vtr::free(pb_graph_node->clock_pins[i][j].output_edges); if (pb_graph_node->clock_pins[i][j].parent_pin_class) - vtr::free(pb_graph_node->clock_pins[i][j].parent_pin_class); + delete[] pb_graph_node->clock_pins[i][j].parent_pin_class; } delete[] pb_graph_node->clock_pins[i]; } - vtr::free(pb_graph_node->input_pins); - vtr::free(pb_graph_node->output_pins); - vtr::free(pb_graph_node->clock_pins); + delete[] pb_graph_node->input_pins; + delete[] pb_graph_node->output_pins; + delete[] pb_graph_node->clock_pins; - vtr::free(pb_graph_node->num_input_pins); - vtr::free(pb_graph_node->num_output_pins); - vtr::free(pb_graph_node->num_clock_pins); + delete[] pb_graph_node->num_input_pins; + delete[] pb_graph_node->num_output_pins; + delete[] pb_graph_node->num_clock_pins; - vtr::free(pb_graph_node->input_pin_class_size); - vtr::free(pb_graph_node->output_pin_class_size); + delete[] pb_graph_node->input_pin_class_size; + delete[] pb_graph_node->output_pin_class_size; if (pb_graph_node->interconnect_pins) { for (i = 0; i < pb_graph_node->pb_type->num_modes; i++) { @@ -403,19 +371,19 @@ static void free_pb_graph(t_pb_graph_node* pb_graph_node) { t_interconnect_power* interconn_power = interconn->interconnect_power; for (int iport = 0; iport < interconn_power->num_input_ports; ++iport) { - vtr::free(pb_graph_node->interconnect_pins[i][j].input_pins[iport]); + delete[] pb_graph_node->interconnect_pins[i][j].input_pins[iport]; } for (int iport = 0; iport < interconn_power->num_output_ports; ++iport) { - vtr::free(pb_graph_node->interconnect_pins[i][j].output_pins[iport]); + delete[] pb_graph_node->interconnect_pins[i][j].output_pins[iport]; } - vtr::free(pb_graph_node->interconnect_pins[i][j].input_pins); - vtr::free(pb_graph_node->interconnect_pins[i][j].output_pins); + delete[] pb_graph_node->interconnect_pins[i][j].input_pins; + delete[] pb_graph_node->interconnect_pins[i][j].output_pins; } - vtr::free(pb_graph_node->interconnect_pins[i]); + delete[] pb_graph_node->interconnect_pins[i]; } } - vtr::free(pb_graph_node->interconnect_pins); - vtr::free(pb_graph_node->pb_node_power); + delete[] pb_graph_node->interconnect_pins; + delete pb_graph_node->pb_node_power; for (i = 0; i < pb_type->num_modes; i++) { for (j = 0; j < pb_type->modes[i].num_pb_type_children; j++) { diff --git a/libs/libarchfpga/src/physical_types.h b/libs/libarchfpga/src/physical_types.h index e587e0c3a29..4b326dd1f2a 100644 --- a/libs/libarchfpga/src/physical_types.h +++ b/libs/libarchfpga/src/physical_types.h @@ -1235,9 +1235,9 @@ class t_pb_graph_pin { public: t_port* port = nullptr; int pin_number = 0; - t_pb_graph_edge** input_edges = nullptr; /* [0..num_input_edges] */ + std::vector input_edges; /* [0..num_input_edges] */ int num_input_edges = 0; - t_pb_graph_edge** output_edges = nullptr; /* [0..num_output_edges] */ + std::vector output_edges; /* [0..num_output_edges] */ int num_output_edges = 0; t_pb_graph_node* parent_node = nullptr; @@ -1256,9 +1256,9 @@ class t_pb_graph_pin { /* combinational timing information */ int num_pin_timing = 0; /* Number of ipin to opin timing edges*/ - t_pb_graph_pin** pin_timing = nullptr; /* timing edge sink pins [0..num_pin_timing-1]*/ - float* pin_timing_del_max = nullptr; /* primitive ipin to opin max-delay [0..num_pin_timing-1]*/ - float* pin_timing_del_min = nullptr; /* primitive ipin to opin min-delay [0..num_pin_timing-1]*/ + std::vector pin_timing; /* timing edge sink pins [0..num_pin_timing-1]*/ + std::vector pin_timing_del_max; /* primitive ipin to opin max-delay [0..num_pin_timing-1]*/ + std::vector pin_timing_del_min; /* primitive ipin to opin min-delay [0..num_pin_timing-1]*/ int num_pin_timing_del_max_annotated = 0; //The list of valid pin_timing_del_max entries runs from [0..num_pin_timing_del_max_annotated-1] int num_pin_timing_del_min_annotated = 0; //The list of valid pin_timing_del_max entries runs from [0..num_pin_timing_del_min_annotated-1] @@ -1333,7 +1333,7 @@ class t_pb_graph_edge { /* pack pattern info */ int num_pack_patterns; - const char** pack_pattern_names; + std::vector pack_pattern_names; int* pack_pattern_indices; bool infer_pattern; diff --git a/libs/libvtrutil/src/vtr_memory.cpp b/libs/libvtrutil/src/vtr_memory.cpp index bc72e352c97..b1809362dff 100644 --- a/libs/libvtrutil/src/vtr_memory.cpp +++ b/libs/libvtrutil/src/vtr_memory.cpp @@ -6,6 +6,7 @@ #include "vtr_memory.h" #include "vtr_error.h" #include "vtr_util.h" +#include "vtr_log.h" #ifndef __GLIBC__ # include diff --git a/vpr/src/base/read_netlist.cpp b/vpr/src/base/read_netlist.cpp index 7a328565882..2843daa82ca 100644 --- a/vpr/src/base/read_netlist.cpp +++ b/vpr/src/base/read_netlist.cpp @@ -751,10 +751,10 @@ static void processPorts(pugi::xml_node Parent, t_pb* pb, t_pb_routes& pb_route, } } for (j = 0; j < num_sets; j++) { - free(pin_node[j]); + delete[] pin_node[j]; } - free(pin_node); - free(num_ptrs); + delete[] pin_node; + delete[] num_ptrs; if (!found) { vpr_throw(VPR_ERROR_NET_F, netlist_file_name, loc_data.line(Cur), "Unknown interconnect %s connecting to pin %s.\n", @@ -820,10 +820,10 @@ static void processPorts(pugi::xml_node Parent, t_pb* pb, t_pb_routes& pb_route, } } for (j = 0; j < num_sets; j++) { - free(pin_node[j]); + delete[] pin_node[j]; } - free(pin_node); - free(num_ptrs); + delete[] pin_node; + delete[] num_ptrs; if (!found) { vpr_throw(VPR_ERROR_NET_F, netlist_file_name, loc_data.line(Cur), "Unknown interconnect %s connecting to pin %s.\n", diff --git a/vpr/src/base/vpr_context.h b/vpr/src/base/vpr_context.h index eee43e6feaa..b296024192d 100644 --- a/vpr/src/base/vpr_context.h +++ b/vpr/src/base/vpr_context.h @@ -322,7 +322,7 @@ struct ClusteringHelperContext : public Context { t_ext_pin_util_targets target_external_pin_util; ~ClusteringHelperContext() { - free(primitives_list); + delete[] primitives_list; } }; diff --git a/vpr/src/base/vpr_types.cpp b/vpr/src/base/vpr_types.cpp index c92e8966de8..ff1722da3de 100644 --- a/vpr/src/base/vpr_types.cpp +++ b/vpr/src/base/vpr_types.cpp @@ -236,31 +236,31 @@ void free_cluster_placement_stats(t_cluster_placement_stats* cluster_placement_s cur = cluster_placement_stats_list[index].tried; while (cur != nullptr) { next = cur->next_primitive; - free(cur); + delete cur; cur = next; } cur = cluster_placement_stats_list[index].in_flight; while (cur != nullptr) { next = cur->next_primitive; - free(cur); + delete cur; cur = next; } cur = cluster_placement_stats_list[index].invalid; while (cur != nullptr) { next = cur->next_primitive; - free(cur); + delete cur; cur = next; } for (int j = 0; j < cluster_placement_stats_list[index].num_pb_types; j++) { cur = cluster_placement_stats_list[index].valid_primitives[j]->next_primitive; while (cur != nullptr) { next = cur->next_primitive; - free(cur); + delete cur; cur = next; } - free(cluster_placement_stats_list[index].valid_primitives[j]); + delete cluster_placement_stats_list[index].valid_primitives[j]; } - free(cluster_placement_stats_list[index].valid_primitives); + delete[] cluster_placement_stats_list[index].valid_primitives; } - free(cluster_placement_stats_list); + delete[] cluster_placement_stats_list; } diff --git a/vpr/src/pack/cluster.cpp b/vpr/src/pack/cluster.cpp index 8cac315cdab..4f1382a990d 100644 --- a/vpr/src/pack/cluster.cpp +++ b/vpr/src/pack/cluster.cpp @@ -189,8 +189,9 @@ std::map do_clustering(const t_packer_opts& pa get_max_cluster_size_and_pb_depth(helper_ctx.max_cluster_size, max_pb_depth); if (packer_opts.hill_climbing_flag) { - clustering_data.hill_climbing_inputs_avail = (int*)vtr::calloc(helper_ctx.max_cluster_size + 1, - sizeof(int)); + clustering_data.hill_climbing_inputs_avail = new int[helper_ctx.max_cluster_size + 1]; + for (int i = 0; i < helper_ctx.max_cluster_size + 1; i++) + clustering_data.hill_climbing_inputs_avail[i] = 0; } else { clustering_data.hill_climbing_inputs_avail = nullptr; /* if used, die hard */ } diff --git a/vpr/src/pack/cluster_feasibility_filter.cpp b/vpr/src/pack/cluster_feasibility_filter.cpp index 58740b51444..c8ecb987f00 100644 --- a/vpr/src/pack/cluster_feasibility_filter.cpp +++ b/vpr/src/pack/cluster_feasibility_filter.cpp @@ -27,6 +27,7 @@ * Date: May 16, 2012 */ +#include #include "vtr_assert.h" #include "vtr_log.h" #include "vtr_memory.h" @@ -95,7 +96,7 @@ static void alloc_pin_classes_in_pb_graph_node(t_pb_graph_node* pb_graph_node) { /* allocate space */ for (i = 0; i < pb_graph_node->num_input_ports; i++) { for (j = 0; j < pb_graph_node->num_input_pins[i]; j++) { - pb_graph_node->input_pins[i][j].parent_pin_class = (int*)vtr::calloc(pb_graph_node->pb_type->depth, sizeof(int)); + pb_graph_node->input_pins[i][j].parent_pin_class = new int[pb_graph_node->pb_type->depth]; for (k = 0; k < pb_graph_node->pb_type->depth; k++) { pb_graph_node->input_pins[i][j].parent_pin_class[k] = OPEN; } @@ -103,17 +104,19 @@ static void alloc_pin_classes_in_pb_graph_node(t_pb_graph_node* pb_graph_node) { } for (i = 0; i < pb_graph_node->num_output_ports; i++) { for (j = 0; j < pb_graph_node->num_output_pins[i]; j++) { - pb_graph_node->output_pins[i][j].parent_pin_class = (int*)vtr::calloc(pb_graph_node->pb_type->depth, sizeof(int)); - pb_graph_node->output_pins[i][j].list_of_connectable_input_pin_ptrs = (t_pb_graph_pin***)vtr::calloc(pb_graph_node->pb_type->depth, sizeof(t_pb_graph_pin**)); - pb_graph_node->output_pins[i][j].num_connectable_primitive_input_pins = (int*)vtr::calloc(pb_graph_node->pb_type->depth, sizeof(int)); + pb_graph_node->output_pins[i][j].parent_pin_class = new int[pb_graph_node->pb_type->depth]; + pb_graph_node->output_pins[i][j].list_of_connectable_input_pin_ptrs = new t_pb_graph_pin**[pb_graph_node->pb_type->depth]; + pb_graph_node->output_pins[i][j].num_connectable_primitive_input_pins = new int[pb_graph_node->pb_type->depth]; for (k = 0; k < pb_graph_node->pb_type->depth; k++) { + pb_graph_node->output_pins[i][j].list_of_connectable_input_pin_ptrs[k] = nullptr; + pb_graph_node->output_pins[i][j].num_connectable_primitive_input_pins[k] = 0; pb_graph_node->output_pins[i][j].parent_pin_class[k] = OPEN; } } } for (i = 0; i < pb_graph_node->num_clock_ports; i++) { for (j = 0; j < pb_graph_node->num_clock_pins[i]; j++) { - pb_graph_node->clock_pins[i][j].parent_pin_class = (int*)vtr::calloc(pb_graph_node->pb_type->depth, sizeof(int)); + pb_graph_node->clock_pins[i][j].parent_pin_class = new int[pb_graph_node->pb_type->depth]; for (k = 0; k < pb_graph_node->pb_type->depth; k++) { pb_graph_node->clock_pins[i][j].parent_pin_class[k] = OPEN; } @@ -261,9 +264,13 @@ static void load_pin_class_by_depth(t_pb_graph_node* pb_graph_node, if (pb_graph_node->pb_type->depth == depth && !pb_graph_node->is_primitive()) { /* Record pin class information for cluster */ pb_graph_node->num_input_pin_class = *input_count + 1; /* number of input pin classes discovered + 1 for primitive inputs not reachable from cluster input pins */ - pb_graph_node->input_pin_class_size = (int*)vtr::calloc(*input_count + 1, sizeof(int)); + pb_graph_node->input_pin_class_size = new int[*input_count + 1]; + for (i = 0; i < *input_count + 1; i++) /* zero-initializing */ + pb_graph_node->input_pin_class_size[i] = 0; pb_graph_node->num_output_pin_class = *output_count + 1; /* number of output pin classes discovered + 1 for primitive inputs not reachable from cluster input pins */ - pb_graph_node->output_pin_class_size = (int*)vtr::calloc(*output_count + 1, sizeof(int)); + pb_graph_node->output_pin_class_size = new int[*output_count + 1]; + for (i = 0; i < *output_count + 1; i++) /* zero-initializing */ + pb_graph_node->output_pin_class_size[i] = 0; sum_pin_class(pb_graph_node); } } @@ -315,10 +322,24 @@ static void expand_pb_graph_node_and_load_output_to_input_connections(t_pb_graph if (current_pb_graph_pin->is_primitive_pin() && current_pb_graph_pin->port->type == IN_PORT) { reference_pin->num_connectable_primitive_input_pins[depth]++; - reference_pin->list_of_connectable_input_pin_ptrs[depth] = (t_pb_graph_pin**)vtr::realloc( - reference_pin->list_of_connectable_input_pin_ptrs[depth], - reference_pin->num_connectable_primitive_input_pins[depth] - * sizeof(t_pb_graph_pin*)); + + if (reference_pin->num_connectable_primitive_input_pins[depth] - 1 > 0) { + std::vector temp(reference_pin->list_of_connectable_input_pin_ptrs[depth], + reference_pin->list_of_connectable_input_pin_ptrs[depth] + reference_pin->num_connectable_primitive_input_pins[depth] - 1); + + delete[] reference_pin->list_of_connectable_input_pin_ptrs[depth]; + reference_pin->list_of_connectable_input_pin_ptrs[depth] = new t_pb_graph_pin*[reference_pin->num_connectable_primitive_input_pins[depth]]; + for (i = 0; i < reference_pin->num_connectable_primitive_input_pins[depth] - 1; i++) + reference_pin->list_of_connectable_input_pin_ptrs[depth][i] = temp[i]; + + reference_pin->list_of_connectable_input_pin_ptrs[depth][reference_pin->num_connectable_primitive_input_pins[depth] + - 1] + = current_pb_graph_pin; + } + + else { + reference_pin->list_of_connectable_input_pin_ptrs[depth] = new t_pb_graph_pin*[reference_pin->num_connectable_primitive_input_pins[depth]]; + } reference_pin->list_of_connectable_input_pin_ptrs[depth][reference_pin->num_connectable_primitive_input_pins[depth] - 1] = current_pb_graph_pin; diff --git a/vpr/src/pack/cluster_placement.cpp b/vpr/src/pack/cluster_placement.cpp index c22d97fea05..5c021309f32 100644 --- a/vpr/src/pack/cluster_placement.cpp +++ b/vpr/src/pack/cluster_placement.cpp @@ -60,14 +60,16 @@ t_cluster_placement_stats* alloc_and_load_cluster_placement_stats() { auto& device_ctx = g_vpr_ctx.device(); - cluster_placement_stats_list = (t_cluster_placement_stats*)vtr::calloc(device_ctx.logical_block_types.size(), - sizeof(t_cluster_placement_stats)); + cluster_placement_stats_list = new t_cluster_placement_stats[device_ctx.logical_block_types.size()]; + for (const auto& type : device_ctx.logical_block_types) { + cluster_placement_stats_list[type.index] = t_cluster_placement_stats(); if (!is_empty_type(&type)) { - cluster_placement_stats_list[type.index].valid_primitives = (t_cluster_placement_primitive**)vtr::calloc( - get_max_primitives_in_pb_type(type.pb_type) + 1, - sizeof(t_cluster_placement_primitive*)); /* too much memory allocated but shouldn't be a problem */ + cluster_placement_stats_list[type.index].valid_primitives = new t_cluster_placement_primitive*[get_max_primitives_in_pb_type(type.pb_type) + 1]; + for (int i = 0; i < get_max_primitives_in_pb_type(type.pb_type) + 1; i++) + cluster_placement_stats_list[type.index].valid_primitives[i] = nullptr; + /* too much memory allocated but shouldn't be a problem */ cluster_placement_stats_list[type.index].curr_molecule = nullptr; load_cluster_placement_stats_for_pb_graph_node(&cluster_placement_stats_list[type.index], type.pb_graph_head); @@ -259,8 +261,8 @@ static void load_cluster_placement_stats_for_pb_graph_node(t_cluster_placement_s const t_pb_type* pb_type = pb_graph_node->pb_type; bool success; if (pb_type->modes == nullptr) { - placement_primitive = (t_cluster_placement_primitive*)vtr::calloc(1, - sizeof(t_cluster_placement_primitive)); + placement_primitive = new t_cluster_placement_primitive; + *placement_primitive = t_cluster_placement_primitive(); placement_primitive->pb_graph_node = pb_graph_node; placement_primitive->valid = true; pb_graph_node->cluster_placement_primitive = placement_primitive; @@ -272,8 +274,8 @@ static void load_cluster_placement_stats_for_pb_graph_node(t_cluster_placement_s || cluster_placement_stats->valid_primitives[i]->next_primitive->pb_graph_node->pb_type == pb_graph_node->pb_type) { if (cluster_placement_stats->valid_primitives[i] == nullptr) { - cluster_placement_stats->valid_primitives[i] = (t_cluster_placement_primitive*)vtr::calloc(1, - sizeof(t_cluster_placement_primitive)); /* head of linked list is empty, makes it easier to remove nodes later */ + cluster_placement_stats->valid_primitives[i] = new t_cluster_placement_primitive; /* head of linked list is empty, makes it easier to remove nodes later */ + *cluster_placement_stats->valid_primitives[i] = t_cluster_placement_primitive(); cluster_placement_stats->num_pb_types++; } success = true; diff --git a/vpr/src/pack/cluster_util.cpp b/vpr/src/pack/cluster_util.cpp index 3e2528ac0dc..e95a915e0ed 100644 --- a/vpr/src/pack/cluster_util.cpp +++ b/vpr/src/pack/cluster_util.cpp @@ -237,15 +237,15 @@ void free_clustering_data(const t_packer_opts& packer_opts, clustering_data.intra_lb_routing.clear(); if (packer_opts.hill_climbing_flag) - free(clustering_data.hill_climbing_inputs_avail); + delete[] clustering_data.hill_climbing_inputs_avail; for (auto blk_id : cluster_ctx.clb_nlist.blocks()) cluster_ctx.clb_nlist.remove_block(blk_id); cluster_ctx.clb_nlist = ClusteredNetlist(); - free(clustering_data.unclustered_list_head); - free(clustering_data.memory_pool); + delete[] clustering_data.unclustered_list_head; + delete[] clustering_data.memory_pool; } //check the clustering and output it @@ -511,14 +511,15 @@ void alloc_and_init_clustering(const t_molecule_stats& max_molecule_stats, int max_molecule_size; /* alloc and load list of molecules to pack */ - clustering_data.unclustered_list_head = (t_molecule_link*)vtr::calloc(max_molecule_stats.num_used_ext_inputs + 1, sizeof(t_molecule_link)); + clustering_data.unclustered_list_head = new t_molecule_link[max_molecule_stats.num_used_ext_inputs + 1]; unclustered_list_head_size = max_molecule_stats.num_used_ext_inputs + 1; for (int i = 0; i <= max_molecule_stats.num_used_ext_inputs; i++) { + clustering_data.unclustered_list_head[i] = t_molecule_link(); clustering_data.unclustered_list_head[i].next = nullptr; } - molecule_array = (t_pack_molecule**)vtr::malloc(num_molecules * sizeof(t_pack_molecule*)); + molecule_array = new t_pack_molecule*[num_molecules]; cur_molecule = molecules_head; for (int i = 0; i < num_molecules; i++) { VTR_ASSERT(cur_molecule != nullptr); @@ -529,7 +530,7 @@ void alloc_and_init_clustering(const t_molecule_stats& max_molecule_stats, qsort((void*)molecule_array, num_molecules, sizeof(t_pack_molecule*), compare_molecule_gain); - clustering_data.memory_pool = (t_molecule_link*)vtr::malloc(num_molecules * sizeof(t_molecule_link)); + clustering_data.memory_pool = new t_molecule_link[num_molecules]; next_ptr = clustering_data.memory_pool; for (int i = 0; i < num_molecules; i++) { @@ -544,7 +545,7 @@ void alloc_and_init_clustering(const t_molecule_stats& max_molecule_stats, next_ptr++; } - free(molecule_array); + delete[] molecule_array; /* load net info */ auto& atom_ctx = g_vpr_ctx.atom(); @@ -576,7 +577,9 @@ void alloc_and_init_clustering(const t_molecule_stats& max_molecule_stats, } cur_molecule = cur_molecule->next; } - *primitives_list = (t_pb_graph_node**)vtr::calloc(max_molecule_size, sizeof(t_pb_graph_node*)); + *primitives_list = new t_pb_graph_node*[max_molecule_size]; + for (int i = 0; i < max_molecule_size; i++) + (*primitives_list)[i] = nullptr; } /*****************************************/ @@ -811,7 +814,9 @@ void alloc_and_load_pb_stats(t_pb* pb, const int feasible_block_array_size) { pb->pb_stats->lookahead_input_pins_used = std::vector>(pb->pb_graph_node->num_input_pin_class); pb->pb_stats->lookahead_output_pins_used = std::vector>(pb->pb_graph_node->num_output_pin_class); pb->pb_stats->num_feasible_blocks = NOT_VALID; - pb->pb_stats->feasible_blocks = (t_pack_molecule**)vtr::calloc(feasible_block_array_size, sizeof(t_pack_molecule*)); + pb->pb_stats->feasible_blocks = new t_pack_molecule*[feasible_block_array_size]; + for (int i = 0; i < feasible_block_array_size; i++) + pb->pb_stats->feasible_blocks[i] = nullptr; pb->pb_stats->tie_break_high_fanout_net = AtomNetId::INVALID(); diff --git a/vpr/src/pack/lb_type_rr_graph.cpp b/vpr/src/pack/lb_type_rr_graph.cpp index aabb670e24e..81a9437ef10 100644 --- a/vpr/src/pack/lb_type_rr_graph.cpp +++ b/vpr/src/pack/lb_type_rr_graph.cpp @@ -86,13 +86,13 @@ void free_all_lb_type_rr_graph(std::vector* lb_type_rr_graphs if (node->outedges != nullptr) { for (int imode = 0; imode < node->num_modes; imode++) { if (node->outedges[imode] != nullptr) { - free(node->outedges[imode]); + delete[] node->outedges[imode]; } } - free(node->outedges); + delete[] node->outedges; } if (node->num_fanout != nullptr) { - free(node->num_fanout); + delete[] node->num_fanout; } } } @@ -192,11 +192,14 @@ static void alloc_and_load_lb_type_rr_graph_for_type(const t_logical_block_type_ /* External source node drives all inputs going into logic block type */ lb_type_rr_node_graph[ext_source_index].capacity = pb_type->num_input_pins + pb_type->num_clock_pins; lb_type_rr_node_graph[ext_source_index].num_modes = 1; - lb_type_rr_node_graph[ext_source_index].num_fanout = (short*)vtr::malloc(sizeof(short)); + lb_type_rr_node_graph[ext_source_index].num_fanout = new short[1]; lb_type_rr_node_graph[ext_source_index].num_fanout[0] = pb_type->num_input_pins + pb_type->num_clock_pins; - lb_type_rr_node_graph[ext_source_index].outedges = (t_lb_type_rr_node_edge**)vtr::calloc(1, sizeof(t_lb_type_rr_node_edge*)); + lb_type_rr_node_graph[ext_source_index].outedges = new t_lb_type_rr_node_edge*[1]; + lb_type_rr_node_graph[ext_source_index].outedges[0] = nullptr; if (lb_type_rr_node_graph[ext_source_index].num_fanout[0] > 0) { - lb_type_rr_node_graph[ext_source_index].outedges[0] = (t_lb_type_rr_node_edge*)vtr::calloc(lb_type_rr_node_graph[ext_source_index].num_fanout[0], sizeof(t_lb_type_rr_node_edge)); + lb_type_rr_node_graph[ext_source_index].outedges[0] = new t_lb_type_rr_node_edge[lb_type_rr_node_graph[ext_source_index].num_fanout[0]]; + for (int i = 0; i < lb_type_rr_node_graph[ext_source_index].num_fanout[0]; i++) + lb_type_rr_node_graph[ext_source_index].outedges[0][i] = t_lb_type_rr_node_edge(); } lb_type_rr_node_graph[ext_source_index].type = LB_SOURCE; @@ -229,7 +232,7 @@ static void alloc_and_load_lb_type_rr_graph_for_type(const t_logical_block_type_ /* External sink node driven by all outputs exiting logic block type */ lb_type_rr_node_graph[ext_sink_index].capacity = pb_type->num_output_pins; lb_type_rr_node_graph[ext_sink_index].num_modes = 1; - lb_type_rr_node_graph[ext_sink_index].num_fanout = (short*)vtr::malloc(sizeof(short)); + lb_type_rr_node_graph[ext_sink_index].num_fanout = new short[1]; lb_type_rr_node_graph[ext_sink_index].num_fanout[0] = 0; /* Terminal point */ lb_type_rr_node_graph[ext_sink_index].outedges = nullptr; lb_type_rr_node_graph[ext_sink_index].type = LB_SINK; @@ -241,11 +244,14 @@ static void alloc_and_load_lb_type_rr_graph_for_type(const t_logical_block_type_ /* External rr node that drives all existing logic block input pins and is driven by all outputs exiting logic block type */ lb_type_rr_node_graph[ext_rr_index].capacity = pb_type->num_output_pins; lb_type_rr_node_graph[ext_rr_index].num_modes = 1; - lb_type_rr_node_graph[ext_rr_index].num_fanout = (short*)vtr::malloc(sizeof(short)); + lb_type_rr_node_graph[ext_rr_index].num_fanout = new short[1]; lb_type_rr_node_graph[ext_rr_index].num_fanout[0] = pb_type->num_input_pins + pb_type->num_clock_pins + 1; - lb_type_rr_node_graph[ext_rr_index].outedges = (t_lb_type_rr_node_edge**)vtr::calloc(1, sizeof(t_lb_type_rr_node_edge*)); + lb_type_rr_node_graph[ext_rr_index].outedges = new t_lb_type_rr_node_edge*[1]; + lb_type_rr_node_graph[ext_rr_index].outedges[0] = nullptr; if (lb_type_rr_node_graph[ext_rr_index].num_fanout[0] > 0) { - lb_type_rr_node_graph[ext_rr_index].outedges[0] = (t_lb_type_rr_node_edge*)vtr::calloc(lb_type_rr_node_graph[ext_rr_index].num_fanout[0], sizeof(t_lb_type_rr_node_edge)); + lb_type_rr_node_graph[ext_rr_index].outedges[0] = new t_lb_type_rr_node_edge[lb_type_rr_node_graph[ext_rr_index].num_fanout[0]]; + for (int i = 0; i < lb_type_rr_node_graph[ext_rr_index].num_fanout[0]; i++) + lb_type_rr_node_graph[ext_rr_index].outedges[0][i] = t_lb_type_rr_node_edge(); } lb_type_rr_node_graph[ext_rr_index].type = LB_INTERMEDIATE; @@ -306,10 +312,12 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n /* alloc and load rr node info */ lb_type_rr_node_graph[pin_index].capacity = 1; lb_type_rr_node_graph[pin_index].num_modes = 1; - lb_type_rr_node_graph[pin_index].num_fanout = (short*)vtr::malloc(sizeof(short)); + lb_type_rr_node_graph[pin_index].num_fanout = new short[1]; lb_type_rr_node_graph[pin_index].num_fanout[0] = 1; - lb_type_rr_node_graph[pin_index].outedges = (t_lb_type_rr_node_edge**)vtr::calloc(1, sizeof(t_lb_type_rr_node_edge*)); - lb_type_rr_node_graph[pin_index].outedges[0] = (t_lb_type_rr_node_edge*)vtr::calloc(1, sizeof(t_lb_type_rr_node_edge)); + lb_type_rr_node_graph[pin_index].outedges = new t_lb_type_rr_node_edge*[1]; + lb_type_rr_node_graph[pin_index].outedges[0] = nullptr; + lb_type_rr_node_graph[pin_index].outedges[0] = new t_lb_type_rr_node_edge[1]; + lb_type_rr_node_graph[pin_index].outedges[0][0] = t_lb_type_rr_node_edge(); lb_type_rr_node_graph[pin_index].outedges[0][0].intrinsic_cost = 1; lb_type_rr_node_graph[pin_index].type = LB_INTERMEDIATE; lb_type_rr_node_graph[pin_index].pb_graph_pin = pb_pin; @@ -322,7 +330,7 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n } else { new_sink.capacity = 1; } - new_sink.num_fanout = (short*)vtr::malloc(sizeof(short)); + new_sink.num_fanout = new short[1]; new_sink.num_fanout[0] = 0; new_sink.type = LB_SINK; sink_index = lb_type_rr_node_graph.size(); @@ -343,8 +351,12 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n /* alloc and load rr node info */ lb_type_rr_node_graph[pin_index].capacity = 1; lb_type_rr_node_graph[pin_index].num_modes = num_modes; - lb_type_rr_node_graph[pin_index].num_fanout = (short*)vtr::calloc(num_modes, sizeof(short)); - lb_type_rr_node_graph[pin_index].outedges = (t_lb_type_rr_node_edge**)vtr::calloc(num_modes, sizeof(t_lb_type_rr_node_edge*)); + lb_type_rr_node_graph[pin_index].num_fanout = new short[num_modes]; + lb_type_rr_node_graph[pin_index].outedges = new t_lb_type_rr_node_edge*[num_modes]; + for (int i = 0; i < num_modes; i++) { + lb_type_rr_node_graph[pin_index].outedges[i] = nullptr; + lb_type_rr_node_graph[pin_index].num_fanout[i] = 0; + } lb_type_rr_node_graph[pin_index].pb_graph_pin = pb_pin; /* Count number of mode-dependant fanout */ @@ -357,7 +369,9 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n /* Allocate space based on fanout */ for (int imode = 0; imode < num_modes; imode++) { - lb_type_rr_node_graph[pin_index].outedges[imode] = (t_lb_type_rr_node_edge*)vtr::calloc(lb_type_rr_node_graph[pin_index].num_fanout[imode], sizeof(t_lb_type_rr_node_edge)); + lb_type_rr_node_graph[pin_index].outedges[imode] = new t_lb_type_rr_node_edge[lb_type_rr_node_graph[pin_index].num_fanout[imode]]; + for (int i = 0; i < lb_type_rr_node_graph[pin_index].num_fanout[imode]; i++) + lb_type_rr_node_graph[pin_index].outedges[imode][i] = t_lb_type_rr_node_edge(); lb_type_rr_node_graph[pin_index].num_fanout[imode] = 0; /* reset to 0 so that we can reuse this variable to populate fanout stats */ } @@ -390,10 +404,10 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n /* alloc and load rr node info */ lb_type_rr_node_graph[pin_index].capacity = 1; lb_type_rr_node_graph[pin_index].num_modes = 1; - lb_type_rr_node_graph[pin_index].num_fanout = (short*)vtr::malloc(sizeof(short)); + lb_type_rr_node_graph[pin_index].num_fanout = new short[1]; lb_type_rr_node_graph[pin_index].num_fanout[0] = 1; - lb_type_rr_node_graph[pin_index].outedges = (t_lb_type_rr_node_edge**)vtr::malloc(sizeof(t_lb_type_rr_node_edge*)); - lb_type_rr_node_graph[pin_index].outedges[0] = (t_lb_type_rr_node_edge*)vtr::malloc(sizeof(t_lb_type_rr_node_edge)); + lb_type_rr_node_graph[pin_index].outedges = new t_lb_type_rr_node_edge*[1]; + lb_type_rr_node_graph[pin_index].outedges[0] = new t_lb_type_rr_node_edge[1]; lb_type_rr_node_graph[pin_index].outedges[0][0].intrinsic_cost = 1; lb_type_rr_node_graph[pin_index].type = LB_INTERMEDIATE; lb_type_rr_node_graph[pin_index].pb_graph_pin = pb_pin; @@ -406,7 +420,7 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n } else { new_sink.capacity = 1; } - new_sink.num_fanout = (short*)vtr::malloc(sizeof(short)); + new_sink.num_fanout = new short[1]; new_sink.num_fanout[0] = 0; new_sink.type = LB_SINK; sink_index = lb_type_rr_node_graph.size(); @@ -436,8 +450,12 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n /* alloc and load rr node info */ lb_type_rr_node_graph[pin_index].capacity = 1; lb_type_rr_node_graph[pin_index].num_modes = num_modes; - lb_type_rr_node_graph[pin_index].num_fanout = (short*)vtr::calloc(num_modes, sizeof(short)); - lb_type_rr_node_graph[pin_index].outedges = (t_lb_type_rr_node_edge**)vtr::calloc(num_modes, sizeof(t_lb_type_rr_node_edge*)); + lb_type_rr_node_graph[pin_index].num_fanout = new short[num_modes]; + lb_type_rr_node_graph[pin_index].outedges = new t_lb_type_rr_node_edge*[num_modes]; + for (int i = 0; i < num_modes; i++) { + lb_type_rr_node_graph[pin_index].outedges[i] = nullptr; + lb_type_rr_node_graph[pin_index].num_fanout[i] = 0; + } lb_type_rr_node_graph[pin_index].pb_graph_pin = pb_pin; /* Count number of mode-dependant out-going edges */ @@ -450,7 +468,10 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n /* Allocate space based on fanout */ for (int imode = 0; imode < num_modes; imode++) { - lb_type_rr_node_graph[pin_index].outedges[imode] = (t_lb_type_rr_node_edge*)vtr::calloc(lb_type_rr_node_graph[pin_index].num_fanout[imode], sizeof(t_lb_type_rr_node_edge)); + lb_type_rr_node_graph[pin_index].outedges[imode] = new t_lb_type_rr_node_edge[lb_type_rr_node_graph[pin_index].num_fanout[imode]]; + for (int i = 0; i < lb_type_rr_node_graph[pin_index].num_fanout[imode]; i++) { + lb_type_rr_node_graph[pin_index].outedges[imode][i] = t_lb_type_rr_node_edge(); + } lb_type_rr_node_graph[pin_index].num_fanout[imode] = 0; /* reset to 0 so that we can reuse this variable to populate fanout stats */ } @@ -484,15 +505,21 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n /* alloc and load rr node info */ lb_type_rr_node_graph[pin_index].capacity = 1; lb_type_rr_node_graph[pin_index].num_modes = num_modes; - lb_type_rr_node_graph[pin_index].num_fanout = (short*)vtr::calloc(num_modes, sizeof(short)); - lb_type_rr_node_graph[pin_index].outedges = (t_lb_type_rr_node_edge**)vtr::calloc(num_modes, sizeof(t_lb_type_rr_node_edge*)); + lb_type_rr_node_graph[pin_index].num_fanout = new short[num_modes]; + lb_type_rr_node_graph[pin_index].outedges = new t_lb_type_rr_node_edge*[num_modes]; + for (int i = 0; i < num_modes; i++) { + lb_type_rr_node_graph[pin_index].outedges[i] = nullptr; + lb_type_rr_node_graph[pin_index].num_fanout[i] = 0; + } lb_type_rr_node_graph[pin_index].pb_graph_pin = pb_pin; /* One edge to external sinks */ lb_type_rr_node_graph[pin_index].num_fanout[0] = 1; /* Allocate space based on fanout */ - lb_type_rr_node_graph[pin_index].outedges[0] = (t_lb_type_rr_node_edge*)vtr::calloc(lb_type_rr_node_graph[pin_index].num_fanout[0], sizeof(t_lb_type_rr_node_edge)); + lb_type_rr_node_graph[pin_index].outedges[0] = new t_lb_type_rr_node_edge[lb_type_rr_node_graph[pin_index].num_fanout[0]]; + for (int i = 0; i < lb_type_rr_node_graph[pin_index].num_fanout[0]; i++) + lb_type_rr_node_graph[pin_index].outedges[0][i] = t_lb_type_rr_node_edge(); /* Load one edge to external opin */; lb_type_rr_node_graph[pin_index].outedges[0][0].node_index = ext_rr_index; @@ -511,8 +538,12 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n /* alloc and load rr node info */ lb_type_rr_node_graph[pin_index].capacity = 1; lb_type_rr_node_graph[pin_index].num_modes = num_modes; - lb_type_rr_node_graph[pin_index].num_fanout = (short*)vtr::calloc(num_modes, sizeof(short)); - lb_type_rr_node_graph[pin_index].outedges = (t_lb_type_rr_node_edge**)vtr::calloc(num_modes, sizeof(t_lb_type_rr_node_edge*)); + lb_type_rr_node_graph[pin_index].num_fanout = new short[num_modes]; + lb_type_rr_node_graph[pin_index].outedges = new t_lb_type_rr_node_edge*[num_modes]; + for (int i = 0; i < num_modes; i++) { + lb_type_rr_node_graph[pin_index].outedges[i] = nullptr; + lb_type_rr_node_graph[pin_index].num_fanout[i] = 0; + } lb_type_rr_node_graph[pin_index].pb_graph_pin = pb_pin; /* Count number of mode-dependant out-going edges */ @@ -525,7 +556,9 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n /* Allocate space based on fanout */ for (int imode = 0; imode < num_modes; imode++) { - lb_type_rr_node_graph[pin_index].outedges[imode] = (t_lb_type_rr_node_edge*)vtr::calloc(lb_type_rr_node_graph[pin_index].num_fanout[imode], sizeof(t_lb_type_rr_node_edge)); + lb_type_rr_node_graph[pin_index].outedges[imode] = new t_lb_type_rr_node_edge[lb_type_rr_node_graph[pin_index].num_fanout[imode]]; + for (int i = 0; i < lb_type_rr_node_graph[pin_index].num_fanout[imode]; i++) + lb_type_rr_node_graph[pin_index].outedges[imode][i] = t_lb_type_rr_node_edge(); lb_type_rr_node_graph[pin_index].num_fanout[imode] = 0; /* reset to 0 so that we can reuse this variable to populate fanout stats */ } @@ -557,8 +590,12 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n /* alloc and load rr node info */ lb_type_rr_node_graph[pin_index].capacity = 1; lb_type_rr_node_graph[pin_index].num_modes = num_modes; - lb_type_rr_node_graph[pin_index].num_fanout = (short*)vtr::calloc(num_modes, sizeof(short)); - lb_type_rr_node_graph[pin_index].outedges = (t_lb_type_rr_node_edge**)vtr::calloc(num_modes, sizeof(t_lb_type_rr_node_edge*)); + lb_type_rr_node_graph[pin_index].num_fanout = new short[num_modes]; + lb_type_rr_node_graph[pin_index].outedges = new t_lb_type_rr_node_edge*[num_modes]; + for (int i = 0; i < num_modes; i++) { + lb_type_rr_node_graph[pin_index].outedges[i] = nullptr; + lb_type_rr_node_graph[pin_index].num_fanout[i] = 0; + } lb_type_rr_node_graph[pin_index].pb_graph_pin = pb_pin; /* Count number of mode-dependant out-going edges */ @@ -571,7 +608,9 @@ static void alloc_and_load_lb_type_rr_graph_for_pb_graph_node(const t_pb_graph_n /* Allocate space based on fanout */ for (int imode = 0; imode < num_modes; imode++) { - lb_type_rr_node_graph[pin_index].outedges[imode] = (t_lb_type_rr_node_edge*)vtr::calloc(lb_type_rr_node_graph[pin_index].num_fanout[imode], sizeof(t_lb_type_rr_node_edge)); + lb_type_rr_node_graph[pin_index].outedges[imode] = new t_lb_type_rr_node_edge[lb_type_rr_node_graph[pin_index].num_fanout[imode]]; + for (int i = 0; i < lb_type_rr_node_graph[pin_index].num_fanout[imode]; i++) + lb_type_rr_node_graph[pin_index].outedges[imode][i] = t_lb_type_rr_node_edge(); lb_type_rr_node_graph[pin_index].num_fanout[imode] = 0; /* reset to 0 so that we can reuse this variable to populate fanout stats */ } diff --git a/vpr/src/pack/output_clustering.cpp b/vpr/src/pack/output_clustering.cpp index 233bbb7ecac..f9781eeb02a 100644 --- a/vpr/src/pack/output_clustering.cpp +++ b/vpr/src/pack/output_clustering.cpp @@ -52,9 +52,15 @@ static void print_stats() { num_clb_types = num_clb_inputs_used = num_clb_outputs_used = nullptr; - num_clb_types = (int*)vtr::calloc(device_ctx.logical_block_types.size(), sizeof(int)); - num_clb_inputs_used = (int*)vtr::calloc(device_ctx.logical_block_types.size(), sizeof(int)); - num_clb_outputs_used = (int*)vtr::calloc(device_ctx.logical_block_types.size(), sizeof(int)); + num_clb_types = new int[device_ctx.logical_block_types.size()]; + num_clb_inputs_used = new int[device_ctx.logical_block_types.size()]; + num_clb_outputs_used = new int[device_ctx.logical_block_types.size()]; + + for (int i = 0; i < (int)device_ctx.logical_block_types.size(); i++) { + num_clb_types[i] = 0; + num_clb_inputs_used[i] = 0; + num_clb_outputs_used[i] = 0; + } for (auto net_id : atom_ctx.nlist.nets()) { nets_absorbed[net_id] = true; @@ -124,9 +130,9 @@ static void print_stats() { } VTR_LOG("Absorbed logical nets %d out of %d nets, %d nets not absorbed.\n", total_nets_absorbed, (int)atom_ctx.nlist.nets().size(), (int)atom_ctx.nlist.nets().size() - total_nets_absorbed); - free(num_clb_types); - free(num_clb_inputs_used); - free(num_clb_outputs_used); + delete[] num_clb_types; + delete[] num_clb_inputs_used; + delete[] num_clb_outputs_used; /* TODO: print more stats */ } diff --git a/vpr/src/pack/pb_type_graph.cpp b/vpr/src/pack/pb_type_graph.cpp index 7a536cb0e23..fe5bc75c0cc 100644 --- a/vpr/src/pack/pb_type_graph.cpp +++ b/vpr/src/pack/pb_type_graph.cpp @@ -125,7 +125,8 @@ void alloc_and_load_all_pb_graphs(bool load_power_structures) { for (auto& type : device_ctx.logical_block_types) { if (type.pb_type) { - type.pb_graph_head = (t_pb_graph_node*)vtr::calloc(1, sizeof(t_pb_graph_node)); + type.pb_graph_head = new t_pb_graph_node; + *type.pb_graph_head = t_pb_graph_node(); int pin_count_in_cluster = 0; alloc_and_load_pb_graph(type.pb_graph_head, nullptr, type.pb_type, 0, load_power_structures, pin_count_in_cluster); @@ -219,13 +220,20 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node, } } - pb_graph_node->num_input_pins = (int*)vtr::calloc(pb_graph_node->num_input_ports, sizeof(int)); - pb_graph_node->num_output_pins = (int*)vtr::calloc(pb_graph_node->num_output_ports, sizeof(int)); - pb_graph_node->num_clock_pins = (int*)vtr::calloc(pb_graph_node->num_clock_ports, sizeof(int)); + if (pb_graph_node->num_input_ports > 0) { + pb_graph_node->num_input_pins = new int[pb_graph_node->num_input_ports]{0}; + pb_graph_node->input_pins = new t_pb_graph_pin* [pb_graph_node->num_input_ports] { nullptr }; + } + + if (pb_graph_node->num_output_ports > 0) { + pb_graph_node->num_output_pins = new int[pb_graph_node->num_output_ports]{0}; + pb_graph_node->output_pins = new t_pb_graph_pin* [pb_graph_node->num_output_ports] { nullptr }; + } - pb_graph_node->input_pins = (t_pb_graph_pin**)vtr::calloc(pb_graph_node->num_input_ports, sizeof(t_pb_graph_pin*)); - pb_graph_node->output_pins = (t_pb_graph_pin**)vtr::calloc(pb_graph_node->num_output_ports, sizeof(t_pb_graph_pin*)); - pb_graph_node->clock_pins = (t_pb_graph_pin**)vtr::calloc(pb_graph_node->num_clock_ports, sizeof(t_pb_graph_pin*)); + if (pb_graph_node->num_clock_ports > 0) { + pb_graph_node->num_clock_pins = new int[pb_graph_node->num_clock_ports]{0}; + pb_graph_node->clock_pins = new t_pb_graph_pin* [pb_graph_node->num_clock_ports] { nullptr }; + } i_input = i_output = i_clockport = 0; for (i = 0; i < pb_type->num_ports; i++) { @@ -294,14 +302,15 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node, /* Power */ if (load_power_structures) { - pb_graph_node->pb_node_power = (t_pb_graph_node_power*)vtr::calloc(1, - sizeof(t_pb_graph_node_power)); + pb_graph_node->pb_node_power = new t_pb_graph_node_power; + *pb_graph_node->pb_node_power = t_pb_graph_node_power(); pb_graph_node->pb_node_power->transistor_cnt_buffers = 0.; pb_graph_node->pb_node_power->transistor_cnt_interc = 0.; pb_graph_node->pb_node_power->transistor_cnt_pb_children = 0.; } /* Allocate and load child nodes for each mode and create interconnect in each mode */ + pb_graph_node->child_pb_graph_nodes = (t_pb_graph_node***)vtr::calloc(pb_type->num_modes, sizeof(t_pb_graph_node**)); for (i = 0; i < pb_type->num_modes; i++) { pb_graph_node->child_pb_graph_nodes[i] = (t_pb_graph_node**)vtr::calloc(pb_type->modes[i].num_pb_type_children, @@ -316,8 +325,10 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node, } } - pb_graph_node->interconnect_pins = (t_interconnect_pins**)vtr::calloc(pb_type->num_modes, sizeof(t_interconnect_pins*)); + pb_graph_node->interconnect_pins = new t_interconnect_pins*[pb_type->num_modes]; + for (i = 0; i < pb_type->num_modes; i++) { + pb_graph_node->interconnect_pins[i] = nullptr; /* Create interconnect for mode */ alloc_and_load_mode_interconnect(pb_graph_node, pb_graph_node->child_pb_graph_nodes[i], &pb_type->modes[i], @@ -345,20 +356,20 @@ void free_pb_graph_edges() { cur_num = num_edges_head; edges = (t_pb_graph_edge*)cur->data_vptr; for (int i = 0; i < (intptr_t)cur_num->data_vptr; i++) { - vtr::free(edges[i].input_pins); - vtr::free(edges[i].output_pins); + delete[] edges[i].input_pins; + delete[] edges[i].output_pins; if (edges[i].pack_pattern_indices) { - vtr::free(edges[i].pack_pattern_indices); - } - if (edges[i].pack_pattern_names) { - vtr::free(edges[i].pack_pattern_names); + delete[] edges[i].pack_pattern_indices; } + // if (edges[i].pack_pattern_names) { + // vtr::free(edges[i].pack_pattern_names); + // } } edges_head = edges_head->next; num_edges_head = num_edges_head->next; - vtr::free(edges); - vtr::free(cur_num); - vtr::free(cur); + delete[] edges; + delete cur_num; + delete cur; } } @@ -407,17 +418,13 @@ static void alloc_and_load_interconnect_pins(t_interconnect_pins* interc_pins, interconnect->interconnect_power->port_info_initialized = true; } - interc_pins->input_pins = (t_pb_graph_pin***)vtr::calloc(num_input_sets, - sizeof(t_pb_graph_pin**)); + interc_pins->input_pins = new t_pb_graph_pin**[num_input_sets]; for (set_idx = 0; set_idx < num_input_sets; set_idx++) { - interc_pins->input_pins[set_idx] = (t_pb_graph_pin**)vtr::calloc(interconnect->interconnect_power->num_pins_per_port, - sizeof(t_pb_graph_pin*)); + interc_pins->input_pins[set_idx] = new t_pb_graph_pin*[interconnect->interconnect_power->num_pins_per_port]; } - interc_pins->output_pins = (t_pb_graph_pin***)vtr::calloc(1, - sizeof(t_pb_graph_pin**)); - interc_pins->output_pins[0] = (t_pb_graph_pin**)vtr::calloc(interconnect->interconnect_power->num_pins_per_port, - sizeof(t_pb_graph_pin*)); + interc_pins->output_pins = new t_pb_graph_pin**[1]; + interc_pins->output_pins[0] = new t_pb_graph_pin*[interconnect->interconnect_power->num_pins_per_port]; for (pin_idx = 0; pin_idx < interconnect->interconnect_power->num_pins_per_port; pin_idx++) { for (set_idx = 0; set_idx < num_input_sets; set_idx++) { @@ -462,11 +469,9 @@ static void alloc_and_load_interconnect_pins(t_interconnect_pins* interc_pins, } /* Input Pins */ - interc_pins->input_pins = (t_pb_graph_pin***)vtr::calloc(interconnect->interconnect_power->num_input_ports, - sizeof(t_pb_graph_pin**)); + interc_pins->input_pins = new t_pb_graph_pin**[interconnect->interconnect_power->num_input_ports]; for (port_idx = 0; port_idx < interconnect->interconnect_power->num_input_ports; port_idx++) { - interc_pins->input_pins[port_idx] = (t_pb_graph_pin**)vtr::calloc(interconnect->interconnect_power->num_pins_per_port, - sizeof(t_pb_graph_pin*)); + interc_pins->input_pins[port_idx] = new t_pb_graph_pin*[interconnect->interconnect_power->num_pins_per_port]; } num_ports = 0; for (set_idx = 0; set_idx < num_input_sets; set_idx++) { @@ -476,11 +481,9 @@ static void alloc_and_load_interconnect_pins(t_interconnect_pins* interc_pins, } /* Output Pins */ - interc_pins->output_pins = (t_pb_graph_pin***)vtr::calloc(interconnect->interconnect_power->num_output_ports, - sizeof(t_pb_graph_pin**)); + interc_pins->output_pins = new t_pb_graph_pin**[interconnect->interconnect_power->num_output_ports]; for (port_idx = 0; port_idx < interconnect->interconnect_power->num_output_ports; port_idx++) { - interc_pins->output_pins[port_idx] = (t_pb_graph_pin**)vtr::calloc(interconnect->interconnect_power->num_pins_per_port, - sizeof(t_pb_graph_pin*)); + interc_pins->output_pins[port_idx] = new t_pb_graph_pin*[interconnect->interconnect_power->num_pins_per_port]; } num_ports = 0; for (set_idx = 0; set_idx < num_output_sets; set_idx++) { @@ -513,8 +516,11 @@ static void alloc_and_load_mode_interconnect(t_pb_graph_node* pb_graph_parent_no if (load_power_structures) { VTR_ASSERT(pb_graph_parent_node->interconnect_pins[mode->index] == nullptr); - pb_graph_parent_node->interconnect_pins[mode->index] = (t_interconnect_pins*)vtr::calloc(mode->num_interconnect, - sizeof(t_interconnect_pins)); + if (mode->num_interconnect > 0) { + pb_graph_parent_node->interconnect_pins[mode->index] = new t_interconnect_pins[mode->num_interconnect]; + } + for (i = 0; i < mode->num_interconnect; i++) + pb_graph_parent_node->interconnect_pins[mode->index][i] = t_interconnect_pins(); } for (i = 0; i < mode->num_interconnect; i++) { @@ -573,15 +579,15 @@ static void alloc_and_load_mode_interconnect(t_pb_graph_node* pb_graph_parent_no mode->interconnect[i].output_string); } for (j = 0; j < num_input_pb_graph_node_sets; j++) { - vtr::free(input_pb_graph_node_pins[j]); + delete[] input_pb_graph_node_pins[j]; } - vtr::free(input_pb_graph_node_pins); + delete[](input_pb_graph_node_pins); for (j = 0; j < num_output_pb_graph_node_sets; j++) { - vtr::free(output_pb_graph_node_pins[j]); + delete[] output_pb_graph_node_pins[j]; } - vtr::free(output_pb_graph_node_pins); - vtr::free(num_input_pb_graph_node_pins); - vtr::free(num_output_pb_graph_node_pins); + delete[] output_pb_graph_node_pins; + delete[] num_input_pb_graph_node_pins; + delete[] num_output_pb_graph_node_pins; } } @@ -638,9 +644,12 @@ t_pb_graph_pin*** alloc_and_load_port_pin_ptrs_from_string(const int line_num, "No matching '{' for '}' in port %s\n", port_string); } - pb_graph_pins = (t_pb_graph_pin***)vtr::calloc(*num_sets, - sizeof(t_pb_graph_pin**)); - *num_ptrs = (int*)vtr::calloc(*num_sets, sizeof(int)); + pb_graph_pins = new t_pb_graph_pin**[*num_sets]; + *num_ptrs = new int[*num_sets]; + for (i = 0; i < *num_sets; i++) { + pb_graph_pins[i] = nullptr; + (*num_ptrs)[i] = 0; + } curr_set = 0; for (i = 0; i < num_tokens; i++) { @@ -712,33 +721,27 @@ static void alloc_and_load_complete_interc_edges(t_interconnect* interconnect, out_count += num_output_ptrs[i_outset]; } - edges = (t_pb_graph_edge*)vtr::calloc(in_count * out_count, sizeof(t_pb_graph_edge)); - cur = (vtr::t_linked_vptr*)vtr::malloc(sizeof(vtr::t_linked_vptr)); + edges = new t_pb_graph_edge[in_count * out_count]; + for (int i = 0; i < (in_count * out_count); i++) + edges[i] = t_pb_graph_edge(); + cur = new vtr::t_linked_vptr; cur->next = edges_head; edges_head = cur; cur->data_vptr = (void*)edges; - cur = (vtr::t_linked_vptr*)vtr::malloc(sizeof(vtr::t_linked_vptr)); + cur = new vtr::t_linked_vptr; cur->next = num_edges_head; num_edges_head = cur; cur->data_vptr = (void*)((intptr_t)in_count * out_count); for (i_inset = 0; i_inset < num_input_sets; i_inset++) { for (i_inpin = 0; i_inpin < num_input_ptrs[i_inset]; i_inpin++) { - input_pb_graph_node_pin_ptrs[i_inset][i_inpin]->output_edges = (t_pb_graph_edge**)vtr::realloc( - input_pb_graph_node_pin_ptrs[i_inset][i_inpin]->output_edges, - (input_pb_graph_node_pin_ptrs[i_inset][i_inpin]->num_output_edges - + out_count) - * sizeof(t_pb_graph_edge*)); + input_pb_graph_node_pin_ptrs[i_inset][i_inpin]->output_edges.resize(input_pb_graph_node_pin_ptrs[i_inset][i_inpin]->num_output_edges + out_count); } } for (i_outset = 0; i_outset < num_output_sets; i_outset++) { for (i_outpin = 0; i_outpin < num_output_ptrs[i_outset]; i_outpin++) { - output_pb_graph_node_pin_ptrs[i_outset][i_outpin]->input_edges = (t_pb_graph_edge**)vtr::realloc( - output_pb_graph_node_pin_ptrs[i_outset][i_outpin]->input_edges, - (output_pb_graph_node_pin_ptrs[i_outset][i_outpin]->num_input_edges - + in_count) - * sizeof(t_pb_graph_edge*)); + output_pb_graph_node_pin_ptrs[i_outset][i_outpin]->input_edges.resize(output_pb_graph_node_pin_ptrs[i_outset][i_outpin]->num_input_edges + in_count); } } @@ -755,10 +758,10 @@ static void alloc_and_load_complete_interc_edges(t_interconnect* interconnect, output_pb_graph_node_pin_ptrs[i_outset][i_outpin]->num_input_edges++; edges[i_edge].num_input_pins = 1; - edges[i_edge].input_pins = (t_pb_graph_pin**)vtr::malloc(sizeof(t_pb_graph_pin*)); + edges[i_edge].input_pins = new t_pb_graph_pin*[1]; edges[i_edge].input_pins[0] = input_pb_graph_node_pin_ptrs[i_inset][i_inpin]; edges[i_edge].num_output_pins = 1; - edges[i_edge].output_pins = (t_pb_graph_pin**)vtr::malloc(sizeof(t_pb_graph_pin*)); + edges[i_edge].output_pins = new t_pb_graph_pin*[1]; edges[i_edge].output_pins[0] = output_pb_graph_node_pin_ptrs[i_outset][i_outpin]; edges[i_edge].interconnect = interconnect; @@ -798,12 +801,14 @@ static void alloc_and_load_direct_interc_edges(t_interconnect* interconnect, } /* Allocate memory for edges */ - t_pb_graph_edge* edges = (t_pb_graph_edge*)vtr::calloc(pins_per_set * num_output_sets, sizeof(t_pb_graph_edge)); - vtr::t_linked_vptr* cur = (vtr::t_linked_vptr*)vtr::malloc(sizeof(vtr::t_linked_vptr)); + t_pb_graph_edge* edges = new t_pb_graph_edge[pins_per_set * num_output_sets]; + for (int i = 0; i < (pins_per_set * num_output_sets); i++) + edges[i] = t_pb_graph_edge(); + vtr::t_linked_vptr* cur = new vtr::t_linked_vptr; cur->next = edges_head; edges_head = cur; cur->data_vptr = (void*)edges; - cur = (vtr::t_linked_vptr*)vtr::malloc(sizeof(vtr::t_linked_vptr)); + cur = new vtr::t_linked_vptr; cur->next = num_edges_head; num_edges_head = cur; cur->data_vptr = (void*)((intptr_t)num_input_ptrs[0]); @@ -813,8 +818,7 @@ static void alloc_and_load_direct_interc_edges(t_interconnect* interconnect, t_pb_graph_pin* input_pin = input_pb_graph_node_pin_ptrs[0][ipin]; //Allocate space for input pin set's out-going edges (one to each out-set) - input_pin->output_edges = (t_pb_graph_edge**)vtr::realloc(input_pin->output_edges, - (input_pin->num_output_edges + num_output_sets) * sizeof(t_pb_graph_edge*)); + input_pin->output_edges.resize(input_pin->num_output_edges + num_output_sets); //Associate each input pin with it's new out-going edges for (int iset = 0; iset < num_output_sets; ++iset) { @@ -830,8 +834,7 @@ static void alloc_and_load_direct_interc_edges(t_interconnect* interconnect, t_pb_graph_pin* output_pin = output_pb_graph_node_pin_ptrs[iset][ipin]; //Allocate space for output pin set's in-coming edge (one edge per pin) - output_pin->input_edges = (t_pb_graph_edge**)vtr::realloc(output_pin->input_edges, - (output_pin->num_input_edges + 1) * sizeof(t_pb_graph_edge*)); + output_pin->input_edges.resize(output_pin->num_input_edges + 1); int ipin_edge = output_pin->num_input_edges; int iedge = iset * pins_per_set + ipin; @@ -846,10 +849,10 @@ static void alloc_and_load_direct_interc_edges(t_interconnect* interconnect, int iedge = iset * pins_per_set + ipin; edges[iedge].num_input_pins = 1; - edges[iedge].input_pins = (t_pb_graph_pin**)vtr::malloc(sizeof(t_pb_graph_pin*)); + edges[iedge].input_pins = new t_pb_graph_pin*[1]; edges[iedge].input_pins[0] = input_pb_graph_node_pin_ptrs[0][ipin]; edges[iedge].num_output_pins = 1; - edges[iedge].output_pins = (t_pb_graph_pin**)vtr::malloc(sizeof(t_pb_graph_pin*)); + edges[iedge].output_pins = new t_pb_graph_pin*[1]; edges[iedge].output_pins[0] = output_pb_graph_node_pin_ptrs[iset][ipin]; edges[iedge].interconnect = interconnect; @@ -879,32 +882,27 @@ static void alloc_and_load_mux_interc_edges(t_interconnect* interconnect, "Mux must have one output\n"); } - edges = (t_pb_graph_edge*)vtr::calloc(num_input_sets, sizeof(t_pb_graph_edge)); - cur = (vtr::t_linked_vptr*)vtr::malloc(sizeof(vtr::t_linked_vptr)); + edges = new t_pb_graph_edge[num_input_sets]; + for (int i = 0; i < (num_input_sets); i++) + edges[i] = t_pb_graph_edge(); + cur = new vtr::t_linked_vptr; cur->next = edges_head; edges_head = cur; cur->data_vptr = (void*)edges; - cur = (vtr::t_linked_vptr*)vtr::malloc(sizeof(vtr::t_linked_vptr)); + cur = new vtr::t_linked_vptr; cur->next = num_edges_head; num_edges_head = cur; cur->data_vptr = (void*)((intptr_t)num_input_sets); for (i_inset = 0; i_inset < num_input_sets; i_inset++) { for (i_inpin = 0; i_inpin < num_input_ptrs[i_inset]; i_inpin++) { - input_pb_graph_node_pin_ptrs[i_inset][i_inpin]->output_edges = (t_pb_graph_edge**)vtr::realloc( - input_pb_graph_node_pin_ptrs[i_inset][i_inpin]->output_edges, - (input_pb_graph_node_pin_ptrs[i_inset][i_inpin]->num_output_edges - + 1) - * sizeof(t_pb_graph_edge*)); + input_pb_graph_node_pin_ptrs[i_inset][i_inpin]->output_edges.resize(input_pb_graph_node_pin_ptrs[i_inset][i_inpin]->num_output_edges + 1); } } for (i_outpin = 0; i_outpin < num_output_ptrs[0]; i_outpin++) { - output_pb_graph_node_pin_ptrs[0][i_outpin]->input_edges = (t_pb_graph_edge**)vtr::realloc( - output_pb_graph_node_pin_ptrs[0][i_outpin]->input_edges, - (output_pb_graph_node_pin_ptrs[0][i_outpin]->num_input_edges - + num_input_sets) - * sizeof(t_pb_graph_edge*)); + output_pb_graph_node_pin_ptrs[0][i_outpin]->input_edges.resize(output_pb_graph_node_pin_ptrs[0][i_outpin]->num_input_edges + + num_input_sets); } /* Load connections between pins and record these updates in the edges */ @@ -913,8 +911,13 @@ static void alloc_and_load_mux_interc_edges(t_interconnect* interconnect, vpr_throw(VPR_ERROR_ARCH, get_arch_file_name(), interconnect->line_num, "# of pins for a particular data line of a mux must equal number of pins at output of mux\n"); } - edges[i_inset].input_pins = (t_pb_graph_pin**)vtr::calloc(num_output_ptrs[0], sizeof(t_pb_graph_pin*)); - edges[i_inset].output_pins = (t_pb_graph_pin**)vtr::calloc(num_output_ptrs[0], sizeof(t_pb_graph_pin*)); + edges[i_inset].input_pins = new t_pb_graph_pin*[num_output_ptrs[0]]; + edges[i_inset].output_pins = new t_pb_graph_pin*[num_output_ptrs[0]]; + for (int i = 0; i < num_output_ptrs[0]; i++) { + edges[i_inset].input_pins[i] = nullptr; + edges[i_inset].output_pins[i] = nullptr; + } + edges[i_inset].num_input_pins = num_output_ptrs[0]; edges[i_inset].num_output_pins = num_output_ptrs[0]; for (i_inpin = 0; i_inpin < num_input_ptrs[i_inset]; i_inpin++) { @@ -1166,7 +1169,17 @@ static bool realloc_and_load_pb_graph_pin_ptrs_at_var(const int line_num, int prev_num_pins = *num_pins; *num_pins += (abs(pb_msb - pb_lsb) + 1) * (abs(pin_msb - pin_lsb) + 1); - *pb_graph_pins = (t_pb_graph_pin**)vtr::realloc(*pb_graph_pins, *num_pins * sizeof(t_pb_graph_pin*)); + + if (prev_num_pins > 0) { + std::vector temp(*pb_graph_pins, *pb_graph_pins + prev_num_pins); + delete[](*pb_graph_pins); + *pb_graph_pins = new t_pb_graph_pin*[*num_pins]; + for (i = 0; i < prev_num_pins; i++) + (*pb_graph_pins)[i] = temp[i]; + } else { + *pb_graph_pins = new t_pb_graph_pin*[*num_pins]; + } + i = j = 0; ipb = pb_lsb; diff --git a/vpr/src/pack/pb_type_graph_annotations.cpp b/vpr/src/pack/pb_type_graph_annotations.cpp index e66da0839e7..63a60188f20 100644 --- a/vpr/src/pack/pb_type_graph_annotations.cpp +++ b/vpr/src/pack/pb_type_graph_annotations.cpp @@ -154,9 +154,7 @@ static void load_pack_pattern_annotations(const int line_num, t_pb_graph_node* p * can use this info to only annotate existing edges */ if (iedge != in_port[i][j]->num_output_edges) { in_port[i][j]->output_edges[iedge]->num_pack_patterns++; - in_port[i][j]->output_edges[iedge]->pack_pattern_names = (const char**)vtr::realloc( - in_port[i][j]->output_edges[iedge]->pack_pattern_names, - sizeof(char*) * in_port[i][j]->output_edges[iedge]->num_pack_patterns); + in_port[i][j]->output_edges[iedge]->pack_pattern_names.resize(in_port[i][j]->output_edges[iedge]->num_pack_patterns); in_port[i][j]->output_edges[iedge]->pack_pattern_names[in_port[i][j]->output_edges[iedge]->num_pack_patterns - 1] = value; } p++; @@ -168,17 +166,17 @@ static void load_pack_pattern_annotations(const int line_num, t_pb_graph_node* p if (in_port != nullptr) { for (i = 0; i < num_in_sets; i++) { - free(in_port[i]); + delete[] in_port[i]; } - free(in_port); - free(num_in_ptrs); + delete[] in_port; + delete[] num_in_ptrs; } if (out_port != nullptr) { for (i = 0; i < num_out_sets; i++) { - free(out_port[i]); + delete[] out_port[i]; } - free(out_port); - free(num_out_ptrs); + delete[] out_port; + delete[] num_out_ptrs; } } @@ -261,9 +259,9 @@ static void load_delay_annotations(const int line_num, } //Allocate and load the delay matrix - delay_matrix = (float**)vtr::malloc(sizeof(float*) * num_inputs); + delay_matrix = new float*[num_inputs]; for (i = 0; i < num_inputs; i++) { - delay_matrix[i] = (float*)vtr::malloc(sizeof(float) * num_outputs); + delay_matrix[i] = new float[num_outputs]; } if (input_format == E_ANNOT_PIN_TO_PIN_MATRIX) { @@ -395,9 +393,9 @@ static void load_delay_annotations(const int line_num, if (num_new_sinks > 0) { //Reallocate src_pin->num_pin_timing += num_new_sinks; - src_pin->pin_timing = (t_pb_graph_pin**)vtr::realloc(src_pin->pin_timing, sizeof(t_pb_graph_pin*) * src_pin->num_pin_timing); - src_pin->pin_timing_del_max = (float*)vtr::realloc(src_pin->pin_timing_del_max, sizeof(float) * src_pin->num_pin_timing); - src_pin->pin_timing_del_min = (float*)vtr::realloc(src_pin->pin_timing_del_min, sizeof(float) * src_pin->num_pin_timing); + src_pin->pin_timing.resize(src_pin->num_pin_timing); + src_pin->pin_timing_del_max.resize(src_pin->num_pin_timing); + src_pin->pin_timing_del_min.resize(src_pin->num_pin_timing); //Store the sink pins and initial delays to invalid size_t ipin_timing = src_pin->num_pin_timing - num_new_sinks; @@ -458,22 +456,22 @@ static void load_delay_annotations(const int line_num, //Clean-up if (in_port != nullptr) { for (i = 0; i < num_in_sets; i++) { - free(in_port[i]); + delete[] in_port[i]; } - free(in_port); - free(num_in_ptrs); + delete[] in_port; + delete[] num_in_ptrs; } if (out_port != nullptr) { for (i = 0; i < num_out_sets; i++) { - free(out_port[i]); + delete[] out_port[i]; } - free(out_port); - free(num_out_ptrs); + delete[] out_port; + delete[] num_out_ptrs; } for (i = 0; i < num_inputs; i++) { - free(delay_matrix[i]); + delete[] delay_matrix[i]; } - free(delay_matrix); + delete[] delay_matrix; } static void inferr_unspecified_pb_graph_node_delays(t_pb_graph_node* pb_graph_node) { diff --git a/vpr/src/pack/prepack.cpp b/vpr/src/pack/prepack.cpp index 9e92ebf995b..1728b73b457 100644 --- a/vpr/src/pack/prepack.cpp +++ b/vpr/src/pack/prepack.cpp @@ -151,7 +151,7 @@ std::vector alloc_and_load_pack_patterns() { * For carry-chains, since carry-chains are typically quite flexible in terms * of size, it is optional whether or not an atom in a netlist matches any * particular block inside the chain */ - list_of_packing_patterns[i].is_block_optional = (bool*)vtr::malloc(L_num_blocks * sizeof(bool)); + list_of_packing_patterns[i].is_block_optional = new bool[L_num_blocks]; for (int k = 0; k < L_num_blocks; k++) { list_of_packing_patterns[i].is_block_optional[k] = false; if (list_of_packing_patterns[i].is_chain && list_of_packing_patterns[i].root_block->block_id != k) { @@ -211,7 +211,7 @@ static void discover_pattern_names_in_pb_graph_node(t_pb_graph_node* pb_graph_no std::string pattern_name(output_edge->pack_pattern_names[m]); int index = (pattern_names.insert({pattern_name, pattern_names.size()}).first)->second; if (!output_edge->pack_pattern_indices) { - output_edge->pack_pattern_indices = (int*)vtr::malloc(output_edge->num_pack_patterns * sizeof(int)); + output_edge->pack_pattern_indices = new int[output_edge->num_pack_patterns]; } output_edge->pack_pattern_indices[m] = index; // if this output edges belongs to a pack pattern. Expand forward starting from @@ -244,7 +244,7 @@ static void discover_pattern_names_in_pb_graph_node(t_pb_graph_node* pb_graph_no std::string pattern_name(output_edge->pack_pattern_names[m]); int index = (pattern_names.insert({pattern_name, pattern_names.size()}).first)->second; if (!output_edge->pack_pattern_indices) { - output_edge->pack_pattern_indices = (int*)vtr::malloc(output_edge->num_pack_patterns * sizeof(int)); + output_edge->pack_pattern_indices = new int[output_edge->num_pack_patterns]; } output_edge->pack_pattern_indices[m] = index; // if this output edges belongs to a pack pattern. Expand forward starting from @@ -277,7 +277,7 @@ static void discover_pattern_names_in_pb_graph_node(t_pb_graph_node* pb_graph_no std::string pattern_name(output_edge->pack_pattern_names[m]); int index = (pattern_names.insert({pattern_name, pattern_names.size()}).first)->second; if (output_edge->pack_pattern_indices == nullptr) { - output_edge->pack_pattern_indices = (int*)vtr::malloc(output_edge->num_pack_patterns * sizeof(int)); + output_edge->pack_pattern_indices = new int[output_edge->num_pack_patterns]; } output_edge->pack_pattern_indices[m] = index; // if this output edges belongs to a pack pattern. Expand forward starting from @@ -352,14 +352,17 @@ void free_list_of_pack_patterns(std::vector& list_of_pack_patte void free_pack_pattern(t_pack_patterns* pack_pattern) { if (pack_pattern) { int num_pack_pattern_blocks = pack_pattern->num_blocks; - t_pack_pattern_block** pattern_block_list = (t_pack_pattern_block**)vtr::calloc(num_pack_pattern_blocks, sizeof(t_pack_pattern_block*)); + t_pack_pattern_block** pattern_block_list = new t_pack_pattern_block*[num_pack_pattern_blocks]; + for (int i = 0; i < num_pack_pattern_blocks; i++) + pattern_block_list[i] = nullptr; + free(pack_pattern->name); - free(pack_pattern->is_block_optional); + delete[] pack_pattern->is_block_optional; free_pack_pattern_block(pack_pattern->root_block, pattern_block_list); for (int j = 0; j < num_pack_pattern_blocks; j++) { - free(pattern_block_list[j]); + delete pattern_block_list[j]; } - free(pattern_block_list); + delete[] pattern_block_list; } } @@ -490,7 +493,8 @@ static void forward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expansi // a primitive that belongs to this pack pattern is found: 1) create a new pattern block, // 2) assign an id to this pattern block, 3) increment the number of found blocks belonging to this // pattern and 4) expand all its edges to find the other primitives that belong to this pattern - destination_block = (t_pack_pattern_block*)vtr::calloc(1, sizeof(t_pack_pattern_block)); + destination_block = new t_pack_pattern_block; + *destination_block = t_pack_pattern_block(); list_of_packing_patterns[curr_pattern_index].base_cost += compute_primitive_base_cost(destination_pb_graph_node); destination_block->block_id = *L_num_blocks; (*L_num_blocks)++; @@ -631,7 +635,8 @@ static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expans /* If this pb_graph_node is part not of the current pattern index, put it in and expand all its edges */ source_block = (t_pack_pattern_block*)source_pb_graph_node->temp_scratch_pad; if (source_block == nullptr || source_block->pattern_index != curr_pattern_index) { - source_block = (t_pack_pattern_block*)vtr::calloc(1, sizeof(t_pack_pattern_block)); + source_block = new t_pack_pattern_block; + *source_block = t_pack_pattern_block(); source_block->block_id = *L_num_blocks; (*L_num_blocks)++; list_of_packing_patterns[curr_pattern_index].base_cost += compute_primitive_base_cost(source_pb_graph_node); @@ -688,7 +693,8 @@ static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expans if (destination_pin != nullptr) { VTR_ASSERT(((t_pack_pattern_block*)source_pb_graph_node->temp_scratch_pad)->pattern_index == curr_pattern_index); source_block = (t_pack_pattern_block*)source_pb_graph_node->temp_scratch_pad; - pack_pattern_connection = (t_pack_pattern_connections*)vtr::calloc(1, sizeof(t_pack_pattern_connections)); + pack_pattern_connection = new t_pack_pattern_connections; + *pack_pattern_connection = t_pack_pattern_connections(); pack_pattern_connection->from_block = source_block; pack_pattern_connection->from_pin = expansion_edge->input_pins[i]; pack_pattern_connection->to_block = destination_block; @@ -696,7 +702,8 @@ static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expans pack_pattern_connection->next = source_block->connections; source_block->connections = pack_pattern_connection; - pack_pattern_connection = (t_pack_pattern_connections*)vtr::calloc(1, sizeof(t_pack_pattern_connections)); + pack_pattern_connection = new t_pack_pattern_connections; + *pack_pattern_connection = t_pack_pattern_connections(); pack_pattern_connection->from_block = source_block; pack_pattern_connection->from_pin = expansion_edge->input_pins[i]; pack_pattern_connection->to_block = destination_block; @@ -779,7 +786,9 @@ t_pack_molecule* alloc_and_load_pack_molecules(t_pack_patterns* list_of_pack_pat auto& atom_ctx = g_vpr_ctx.atom(); auto& atom_mutable_ctx = g_vpr_ctx.mutable_atom(); - is_used = (bool*)vtr::calloc(num_packing_patterns, sizeof(bool)); + is_used = new bool[num_packing_patterns]; + for (i = 0; i < num_packing_patterns; i++) + is_used[i] = false; cur_molecule = list_of_molecules_head = nullptr; @@ -839,7 +848,7 @@ t_pack_molecule* alloc_and_load_pack_molecules(t_pack_patterns* list_of_pack_pat } } } - free(is_used); + delete[] is_used; /* List all atom blocks as a molecule for blocks that do not belong to any molecules. * This allows the packer to be consistent as it now packs molecules only instead of atoms and molecules @@ -908,7 +917,7 @@ static void free_pack_pattern_block(t_pack_pattern_block* pattern_block, t_pack_ free_pack_pattern_block(connection->from_block, pattern_block_list); free_pack_pattern_block(connection->to_block, pattern_block_list); next = connection->next; - free(connection); + delete connection; connection = next; } } diff --git a/vpr/src/util/vpr_utils.cpp b/vpr/src/util/vpr_utils.cpp index e623031e029..61afce15a58 100644 --- a/vpr/src/util/vpr_utils.cpp +++ b/vpr/src/util/vpr_utils.cpp @@ -1401,7 +1401,7 @@ void free_pb_stats(t_pb* pb) { pb->pb_stats->num_pins_of_net_in_pb.clear(); if (pb->pb_stats->feasible_blocks) { - free(pb->pb_stats->feasible_blocks); + delete[] pb->pb_stats->feasible_blocks; } if (!pb->parent_pb) { pb->pb_stats->transitive_fanout_candidates.clear(); diff --git a/vtr_flow/sdc/samples/H.sdc b/vtr_flow/sdc/samples/H.sdc new file mode 100644 index 00000000000..1c4c8288522 --- /dev/null +++ b/vtr_flow/sdc/samples/H.sdc @@ -0,0 +1 @@ +create_clock -period 10000 *