diff --git a/ODIN_II/SRC/adders.cpp b/ODIN_II/SRC/adders.cpp index 28d5b740aac..4bd068c98b5 100644 --- a/ODIN_II/SRC/adders.cpp +++ b/ODIN_II/SRC/adders.cpp @@ -1064,7 +1064,7 @@ void remove_list_node(t_linked_vptr* pre, t_linked_vptr* next) { pre->next = next->next; else pre->next = NULL; - vtr::free(next); + delete next; } /*--------------------------------------------------------------------------- @@ -1434,4 +1434,4 @@ nnode_t* check_missing_ports(nnode_t* node, uintptr_t traverse_mark_number, netl } return new_node; -} \ No newline at end of file +} diff --git a/libs/libvtrutil/src/vtr_list.cpp b/libs/libvtrutil/src/vtr_list.cpp index ce276e2b538..ce354dfe383 100644 --- a/libs/libvtrutil/src/vtr_list.cpp +++ b/libs/libvtrutil/src/vtr_list.cpp @@ -9,24 +9,16 @@ t_linked_vptr* insert_in_vptr_list(t_linked_vptr* head, void* vptr_to_add) { /* Inserts a new element at the head of a linked list of void pointers. * * Returns the new head of the list. */ - t_linked_vptr* linked_vptr; - - linked_vptr = (t_linked_vptr*)vtr::malloc(sizeof(t_linked_vptr)); - - linked_vptr->data_vptr = vptr_to_add; - linked_vptr->next = head; - return (linked_vptr); /* New head of the list */ + return new t_linked_vptr{vptr_to_add, head}; /* New head of the list */ } /* Deletes the element at the head of a linked list of void pointers. * * Returns the new head of the list. */ t_linked_vptr* delete_in_vptr_list(t_linked_vptr* head) { - t_linked_vptr* linked_vptr; - if (head == nullptr) return nullptr; - linked_vptr = head->next; - free(head); + t_linked_vptr* const linked_vptr = head->next; + delete head; return linked_vptr; /* New head of the list */ } diff --git a/libs/libvtrutil/src/vtr_memory.cpp b/libs/libvtrutil/src/vtr_memory.cpp index b1809362dff..39d6b244b13 100644 --- a/libs/libvtrutil/src/vtr_memory.cpp +++ b/libs/libvtrutil/src/vtr_memory.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "vtr_assert.h" #include "vtr_list.h" @@ -43,7 +44,7 @@ void* calloc(size_t nelem, size_t size) { if ((ret = std::calloc(nelem, size)) == nullptr) { throw VtrError("Unable to calloc memory.", __FILE__, __LINE__); } - return (ret); + return ret; } void* malloc(size_t size) { @@ -55,7 +56,7 @@ void* malloc(size_t size) { if ((ret = std::malloc(size)) == nullptr && size != 0) { throw VtrError("Unable to malloc memory.", __FILE__, __LINE__); } - return (ret); + return ret; } void* realloc(void* ptr, size_t size) { @@ -66,7 +67,7 @@ void* realloc(void* ptr, size_t size) { throw VtrError(string_fmt("Unable to realloc memory (ptr=%p, size=%d).", ptr, size), __FILE__, __LINE__); } - return (ret); + return ret; } void* chunk_malloc(size_t size, t_chunk* chunk_info) { @@ -102,7 +103,9 @@ void* chunk_malloc(size_t size, t_chunk* chunk_info) { if ((size_t)(chunk_info->mem_avail) < size) { /* Need to malloc more memory. */ if (size > CHUNK_SIZE) { /* Too big, use standard routine. */ - tmp_ptr = (char*)vtr::malloc(size); + /* Want to allocate a block of memory the size of size. + * i.e. malloc(size) */ + tmp_ptr = new char[size]; /* When debugging, uncomment the code below to see if memory allocation size */ /* makes sense */ @@ -113,11 +116,11 @@ void* chunk_malloc(size_t size, t_chunk* chunk_info) { VTR_ASSERT(chunk_info != nullptr); chunk_info->chunk_ptr_head = insert_in_vptr_list(chunk_info->chunk_ptr_head, tmp_ptr); - return (tmp_ptr); + return tmp_ptr; } if (chunk_info->mem_avail < FRAGMENT_THRESHOLD) { /* Only a small scrap left. */ - chunk_info->next_mem_loc_ptr = (char*)vtr::malloc(CHUNK_SIZE); + chunk_info->next_mem_loc_ptr = new char[CHUNK_SIZE]; chunk_info->mem_avail = CHUNK_SIZE; VTR_ASSERT(chunk_info != nullptr); chunk_info->chunk_ptr_head = insert_in_vptr_list(chunk_info->chunk_ptr_head, chunk_info->next_mem_loc_ptr); @@ -128,10 +131,11 @@ void* chunk_malloc(size_t size, t_chunk* chunk_info) { * to allocate normally. */ else { - tmp_ptr = (char*)vtr::malloc(size); + tmp_ptr = new char[size]; VTR_ASSERT(chunk_info != nullptr); chunk_info->chunk_ptr_head = insert_in_vptr_list(chunk_info->chunk_ptr_head, tmp_ptr); - return (tmp_ptr); + + return tmp_ptr; } } @@ -147,7 +151,7 @@ void* chunk_malloc(size_t size, t_chunk* chunk_info) { tmp_ptr = chunk_info->next_mem_loc_ptr; chunk_info->next_mem_loc_ptr += aligned_size; chunk_info->mem_avail -= aligned_size; - return (tmp_ptr); + return tmp_ptr; } void free_chunk_memory(t_chunk* chunk_info) { @@ -158,11 +162,14 @@ void free_chunk_memory(t_chunk* chunk_info) { curr_ptr = chunk_info->chunk_ptr_head; while (curr_ptr != nullptr) { - free(curr_ptr->data_vptr); /* Free memory "chunk". */ + /* Must cast pointers to type char*, since the're of type void*, which delete can't + * be called on.*/ + delete[]((char*)curr_ptr->data_vptr); /* Free memory "chunk". */ prev_ptr = curr_ptr; curr_ptr = curr_ptr->next; - free(prev_ptr); /* Free memory used to track "chunk". */ + delete (t_linked_vptr*)prev_ptr; /* Free memory used to track "chunk". */ } + chunk_info->chunk_ptr_head = nullptr; chunk_info->mem_avail = 0; chunk_info->next_mem_loc_ptr = nullptr; diff --git a/vpr/src/base/SetupVPR.cpp b/vpr/src/base/SetupVPR.cpp index 062fdaca11b..361543e1e92 100644 --- a/vpr/src/base/SetupVPR.cpp +++ b/vpr/src/base/SetupVPR.cpp @@ -648,9 +648,11 @@ static void SetupPowerOpts(const t_options& Options, t_power_opts* power_opts, t if (power_opts->do_power) { if (!Arch->power) - Arch->power = (t_power_arch*)vtr::malloc(sizeof(t_power_arch)); + Arch->power = new t_power_arch(); + if (!Arch->clocks) - Arch->clocks = (t_clock_arch*)vtr::malloc(sizeof(t_clock_arch)); + Arch->clocks = new t_clock_arch(); + device_ctx.clock_arch = Arch->clocks; } else { Arch->power = nullptr; diff --git a/vpr/src/draw/draw.cpp b/vpr/src/draw/draw.cpp index daff060d12b..f8f26b5f729 100644 --- a/vpr/src/draw/draw.cpp +++ b/vpr/src/draw/draw.cpp @@ -516,8 +516,7 @@ void alloc_draw_structs(const t_arch* arch) { /* Space is allocated for draw_rr_node but not initialized because we do * * not yet know information about the routing resources. */ - draw_state->draw_rr_node = (t_draw_rr_node*)vtr::malloc( - device_ctx.rr_graph.num_nodes() * sizeof(t_draw_rr_node)); + draw_state->draw_rr_node.resize(device_ctx.rr_graph.num_nodes()); draw_state->arch_info = arch; @@ -534,7 +533,6 @@ void free_draw_structs() { * * For safety, set all the array pointers to NULL in case any data * structure gets freed twice. */ - t_draw_state* draw_state = get_draw_state_vars(); t_draw_coords* draw_coords = get_draw_coords_vars(); if (draw_coords != nullptr) { @@ -544,10 +542,6 @@ void free_draw_structs() { draw_coords->tile_y = nullptr; } - if (draw_state != nullptr) { - free(draw_state->draw_rr_node); - draw_state->draw_rr_node = nullptr; - } #else ; #endif /* NO_GRAPHICS */ @@ -569,9 +563,7 @@ void init_draw_coords(float width_val) { /* Each time routing is on screen, need to reallocate the color of each * * rr_node, as the number of rr_nodes may change. */ if (rr_graph.num_nodes() != 0) { - draw_state->draw_rr_node = (t_draw_rr_node*)vtr::realloc( - draw_state->draw_rr_node, - (rr_graph.num_nodes()) * sizeof(t_draw_rr_node)); + draw_state->draw_rr_node.resize(rr_graph.num_nodes()); /*FIXME: the type cast should be eliminated by making draw_rr_node adapt RRNodeId */ for (const RRNodeId& rr_id : rr_graph.nodes()) { draw_state->draw_rr_node[(size_t)rr_id].color = DEFAULT_RR_NODE_COLOR; diff --git a/vpr/src/draw/draw_types.h b/vpr/src/draw/draw_types.h index db989a59777..b97077f6f41 100644 --- a/vpr/src/draw/draw_types.h +++ b/vpr/src/draw/draw_types.h @@ -203,7 +203,7 @@ struct t_draw_state { e_route_type draw_route_type = GLOBAL; char default_message[vtr::bufsize]; vtr::vector net_color; - t_draw_rr_node* draw_rr_node = nullptr; + std::vector draw_rr_node; std::shared_ptr setup_timing_info; const t_arch* arch_info = nullptr; std::shared_ptr color_map = nullptr; diff --git a/vpr/src/pack/cluster_util.cpp b/vpr/src/pack/cluster_util.cpp index e95a915e0ed..3615c12e760 100644 --- a/vpr/src/pack/cluster_util.cpp +++ b/vpr/src/pack/cluster_util.cpp @@ -815,6 +815,7 @@ void alloc_and_load_pb_stats(t_pb* pb, const int feasible_block_array_size) { 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 = 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; diff --git a/vpr/src/place/place_macro.cpp b/vpr/src/place/place_macro.cpp index 9d85960dc23..a743342e2b5 100644 --- a/vpr/src/place/place_macro.cpp +++ b/vpr/src/place/place_macro.cpp @@ -424,17 +424,17 @@ void free_placement_macros_structs() { unsigned int itype; if (f_idirect_from_blk_pin != nullptr) { for (itype = 1; itype < device_ctx.physical_tile_types.size(); itype++) { - free(f_idirect_from_blk_pin[itype]); + delete[](f_idirect_from_blk_pin[itype]); } - free(f_idirect_from_blk_pin); + delete[](f_idirect_from_blk_pin); f_idirect_from_blk_pin = nullptr; } if (f_direct_type_from_blk_pin != nullptr) { for (itype = 1; itype < device_ctx.physical_tile_types.size(); itype++) { - free(f_direct_type_from_blk_pin[itype]); + delete[](f_direct_type_from_blk_pin[itype]); } - free(f_direct_type_from_blk_pin); + delete[](f_direct_type_from_blk_pin); f_direct_type_from_blk_pin = nullptr; } } diff --git a/vpr/src/power/power.cpp b/vpr/src/power/power.cpp index 2d75efcc464..475c1e03679 100644 --- a/vpr/src/power/power.cpp +++ b/vpr/src/power/power.cpp @@ -173,9 +173,9 @@ static void power_usage_primitive(t_power_usage* power_usage, t_pb* pb, t_pb_gra power_ctx.arch->LUT_transistor_size, SRAM_values, input_probabilities, input_densities, power_ctx.solution_inf.T_crit); power_add_usage(power_usage, &sub_power_usage); - free(SRAM_values); - delete[](input_probabilities); - delete[](input_densities); + delete[] SRAM_values; + delete[] input_probabilities; + delete[] input_densities; } else if (strcmp(pb_graph_node->pb_type->blif_model, MODEL_LATCH) == 0) { /* Flip-Flop */ @@ -763,7 +763,7 @@ static void power_usage_clock_single(t_power_usage* power_usage, /* Frees a multiplexer graph */ static void dealloc_mux_graph(t_mux_node* node) { dealloc_mux_graph_rec(node); - free(node); + delete node; } static void dealloc_mux_graph_rec(t_mux_node* node) { @@ -774,7 +774,7 @@ static void dealloc_mux_graph_rec(t_mux_node* node) { for (child_idx = 0; child_idx < node->num_inputs; child_idx++) { dealloc_mux_graph_rec(&node->children[child_idx]); } - free(node->children); + delete[] node->children; } } @@ -1084,7 +1084,7 @@ void power_alloc_and_init_pb_pin(t_pb_graph_pin* pin) { } void power_uninit_pb_pin(t_pb_graph_pin* pin) { - delete (pin->pin_power); + delete pin->pin_power; pin->pin_power = nullptr; } @@ -1197,9 +1197,9 @@ void power_routing_init(const t_det_routing_arch* routing_arch) { } /* Initialize RR Graph Structures */ - rr_node_power = (t_rr_node_power*)vtr::calloc(rr_graph.num_nodes(), - sizeof(t_rr_node_power)); + rr_node_power = new t_rr_node_power[rr_graph.num_nodes()]; for (const RRNodeId& rr_id : device_ctx.rr_graph.nodes()) { + rr_node_power[(size_t)rr_id] = t_rr_node_power(); rr_node_power[(size_t)rr_id].driver_switch_type = OPEN; } @@ -1219,10 +1219,13 @@ void power_routing_init(const t_det_routing_arch* routing_arch) { max_IPIN_fanin = std::max(max_IPIN_fanin, node_fan_in); max_fanin = std::max(max_fanin, node_fan_in); - node_power->in_dens = (float*)vtr::calloc(node_fan_in, - sizeof(float)); - node_power->in_prob = (float*)vtr::calloc(node_fan_in, - sizeof(float)); + node_power->in_dens = new float[node_fan_in]; + node_power->in_prob = new float[node_fan_in]; + for (int i = 0; i < node_fan_in; i++) { + node_power->in_dens[i] = 0; + node_power->in_prob[i] = 0; + } + break; case CHANX: case CHANY: @@ -1238,10 +1241,12 @@ void power_routing_init(const t_det_routing_arch* routing_arch) { max_seg_to_seg_fanout = std::max(max_seg_to_seg_fanout, fanout_to_seg); max_fanin = std::max(max_fanin, node_fan_in); - node_power->in_dens = (float*)vtr::calloc(node_fan_in, - sizeof(float)); - node_power->in_prob = (float*)vtr::calloc(node_fan_in, - sizeof(float)); + node_power->in_dens = new float[node_fan_in]; + node_power->in_prob = new float[node_fan_in]; + for (int i = 0; i < node_fan_in; i++) { + node_power->in_dens[i] = 0; + node_power->in_prob[i] = 0; + } break; default: /* Do nothing */ @@ -1302,15 +1307,16 @@ bool power_init(const char* power_out_filepath, /* Set global power architecture & options */ power_ctx.arch = arch->power; power_ctx.commonly_used = new t_power_commonly_used; - power_ctx.tech = (t_power_tech*)vtr::malloc(sizeof(t_power_tech)); - power_ctx.output = (t_power_output*)vtr::malloc(sizeof(t_power_output)); + power_ctx.tech = new t_power_tech; + power_ctx.output = new t_power_output; /* Set up Logs */ power_ctx.output->num_logs = POWER_LOG_NUM_TYPES; - power_ctx.output->logs = (t_log*)vtr::calloc(power_ctx.output->num_logs, - sizeof(t_log)); - power_ctx.output->logs[POWER_LOG_ERROR].name = vtr::strdup("Errors"); - power_ctx.output->logs[POWER_LOG_WARNING].name = vtr::strdup("Warnings"); + power_ctx.output->logs = new t_log[power_ctx.output->num_logs]; + for (int i = 0; i < power_ctx.output->num_logs; i++) + power_ctx.output->logs[i] = t_log(); + power_ctx.output->logs[POWER_LOG_ERROR].name = "Errors"; + power_ctx.output->logs[POWER_LOG_WARNING].name = "Warnings"; /* Initialize output file */ if (!error) { @@ -1353,8 +1359,6 @@ bool power_init(const char* power_out_filepath, */ bool power_uninit() { int mux_size; - int log_idx; - int msg_idx; auto& device_ctx = g_vpr_ctx.device(); const auto& rr_graph = device_ctx.rr_graph; auto& power_ctx = g_vpr_ctx.power(); @@ -1367,17 +1371,15 @@ bool power_uninit() { case CHANX: case CHANY: case IPIN: - if (rr_graph.node_fan_in(rr_id)) { - free(node_power->in_dens); - free(node_power->in_prob); - } + delete[] node_power->in_dens; + delete[] node_power->in_prob; break; default: /* Do nothing */ break; } } - free(rr_node_power); + delete[] rr_node_power; /* Free mux architectures */ for (std::map::iterator it = power_ctx.commonly_used->mux_info.begin(); @@ -1386,14 +1388,14 @@ bool power_uninit() { for (mux_size = 1; mux_size <= mux_info->mux_arch_max_size; mux_size++) { dealloc_mux_graph(mux_info->mux_arch[mux_size].mux_graph_head); } - free(mux_info->mux_arch); + delete mux_info; } /* Free components */ for (int i = 0; i < POWER_CALLIB_COMPONENT_MAX; ++i) { delete power_ctx.commonly_used->component_callibration[i]; } - free(power_ctx.commonly_used->component_callibration); + delete[] power_ctx.commonly_used->component_callibration; delete power_ctx.commonly_used; @@ -1401,16 +1403,9 @@ bool power_uninit() { if (power_ctx.output->out) { fclose(power_ctx.output->out); } - for (log_idx = 0; log_idx < power_ctx.output->num_logs; log_idx++) { - for (msg_idx = 0; msg_idx < power_ctx.output->logs[log_idx].num_messages; - msg_idx++) { - free(power_ctx.output->logs[log_idx].messages[msg_idx]); - } - free(power_ctx.output->logs[log_idx].messages); - free(power_ctx.output->logs[log_idx].name); - } - free(power_ctx.output->logs); - free(power_ctx.output); + + delete[] power_ctx.output->logs; + delete power_ctx.output; power_pb_pins_uninit(); diff --git a/vpr/src/power/power.h b/vpr/src/power/power.h index b95d74bafc5..42191fafe2d 100644 --- a/vpr/src/power/power.h +++ b/vpr/src/power/power.h @@ -208,15 +208,16 @@ struct t_power_output { }; struct t_log { - char* name; - char** messages; + std::string name; + std::vector messages; int num_messages; }; struct t_power_mux_info { /* Mux architecture information for 0..mux_arch_max_size */ int mux_arch_max_size; - t_mux_arch* mux_arch; + // t_mux_arch* mux_arch; + std::vector mux_arch; }; /** diff --git a/vpr/src/power/power_cmos_tech.cpp b/vpr/src/power/power_cmos_tech.cpp index 2054d88f240..6d8b38ac32e 100644 --- a/vpr/src/power/power_cmos_tech.cpp +++ b/vpr/src/power/power_cmos_tech.cpp @@ -159,8 +159,9 @@ static void power_tech_xml_load_component(pugi::xml_node parent, const pugiutil: static void power_tech_xml_load_components(pugi::xml_node parent, const pugiutil::loc_data& loc_data) { auto& power_ctx = g_vpr_ctx.power(); - power_ctx.commonly_used->component_callibration = (PowerSpicedComponent**)vtr::calloc(POWER_CALLIB_COMPONENT_MAX, - sizeof(PowerSpicedComponent*)); + power_ctx.commonly_used->component_callibration = new PowerSpicedComponent*[POWER_CALLIB_COMPONENT_MAX]; + for (int i = 0; i < POWER_CALLIB_COMPONENT_MAX; i++) + power_ctx.commonly_used->component_callibration[i] = nullptr; power_tech_xml_load_component(parent, loc_data, &power_ctx.commonly_used->component_callibration[POWER_CALLIB_COMPONENT_BUFFER], @@ -196,7 +197,7 @@ static void power_tech_xml_load_nmos_st_leakages(pugi::xml_node parent, const pu num_nmos_sizes = count_children(parent, "nmos", loc_data); power_ctx.tech->num_nmos_leakage_info = num_nmos_sizes; - power_ctx.tech->nmos_leakage_info = (t_power_nmos_leakage_inf*)vtr::calloc(num_nmos_sizes, sizeof(t_power_nmos_leakage_inf)); + power_ctx.tech->nmos_leakage_info = new t_power_nmos_leakage_inf[num_nmos_sizes]; auto me = get_first_child(parent, "nmos", loc_data); nmos_idx = 0; @@ -206,7 +207,7 @@ static void power_tech_xml_load_nmos_st_leakages(pugi::xml_node parent, const pu num_leakage_pairs = count_children(me, "nmos_leakage", loc_data); nmos_info->num_leakage_pairs = num_leakage_pairs; - nmos_info->leakage_pairs = (t_power_nmos_leakage_pair*)vtr::calloc(num_leakage_pairs, sizeof(t_power_nmos_leakage_pair)); + nmos_info->leakage_pairs = new t_power_nmos_leakage_pair[num_leakage_pairs]; auto child = get_first_child(me, "nmos_leakage", loc_data); i = 0; @@ -237,7 +238,7 @@ static void power_tech_xml_load_multiplexer_info(pugi::xml_node parent, const pu num_nmos_sizes = count_children(parent, "nmos", loc_data); VTR_ASSERT(num_nmos_sizes > 0); power_ctx.tech->num_nmos_mux_info = num_nmos_sizes; - power_ctx.tech->nmos_mux_info = (t_power_nmos_mux_inf*)vtr::calloc(num_nmos_sizes, sizeof(t_power_nmos_mux_inf)); + power_ctx.tech->nmos_mux_info = new t_power_nmos_mux_inf[num_nmos_sizes]; auto me = get_first_child(parent, "nmos", loc_data); nmos_idx = 0; @@ -252,7 +253,7 @@ static void power_tech_xml_load_multiplexer_info(pugi::xml_node parent, const pu * they will never be used */ nmos_inf->max_mux_sl_size = 1 + num_mux_sizes; - nmos_inf->mux_voltage_inf = (t_power_mux_volt_inf*)vtr::calloc(nmos_inf->max_mux_sl_size + 1, sizeof(t_power_mux_volt_inf)); + nmos_inf->mux_voltage_inf = new t_power_mux_volt_inf[nmos_inf->max_mux_sl_size + 1]; auto child = get_first_child(me, "multiplexer", loc_data); i = 1; @@ -265,8 +266,8 @@ static void power_tech_xml_load_multiplexer_info(pugi::xml_node parent, const pu num_voltages = count_children(child, "voltages", loc_data); nmos_inf->mux_voltage_inf[i].num_voltage_pairs = num_voltages; - nmos_inf->mux_voltage_inf[i].mux_voltage_pairs = (t_power_mux_volt_pair*)vtr::calloc(num_voltages, - sizeof(t_power_mux_volt_pair)); + + nmos_inf->mux_voltage_inf[i].mux_voltage_pairs = new t_power_mux_volt_pair[num_voltages]; auto gc = get_first_child(child, "voltages", loc_data); j = 0; @@ -314,7 +315,7 @@ static void process_tech_xml_load_transistor_info(pugi::xml_node parent, const p } /* Get long transistor information (W=1,L=2) */ - trans_inf->long_trans_inf = (t_transistor_size_inf*)vtr::malloc(sizeof(t_transistor_size_inf)); + trans_inf->long_trans_inf = new t_transistor_size_inf; auto child = get_single_child(parent, "long_size", loc_data); VTR_ASSERT(get_attribute(child, "L", loc_data).as_int(0) == 2); @@ -330,7 +331,7 @@ static void process_tech_xml_load_transistor_info(pugi::xml_node parent, const p /* Process all transistor sizes */ trans_inf->num_size_entries = count_children(parent, "size", loc_data); - trans_inf->size_inf = (t_transistor_size_inf*)vtr::calloc(trans_inf->num_size_entries, sizeof(t_transistor_size_inf)); + trans_inf->size_inf = new t_transistor_size_inf[trans_inf->num_size_entries]; child = get_first_child(parent, "size", loc_data); i = 0; diff --git a/vpr/src/power/power_sizing.cpp b/vpr/src/power/power_sizing.cpp index a2013d7e234..f5bde09ded4 100644 --- a/vpr/src/power/power_sizing.cpp +++ b/vpr/src/power/power_sizing.cpp @@ -659,7 +659,7 @@ static void power_size_pin_buffers_and_wires(t_pb_graph_pin* pin, bool pin_is_an_input) { int edge_idx; int list_cnt; - t_interconnect** list; + std::vector list; bool found; int i; @@ -714,7 +714,6 @@ static void power_size_pin_buffers_and_wires(t_pb_graph_pin* pin, * be higher)*/ /* Loop through all edges, building a list of interconnect that this pin drives */ - list = nullptr; list_cnt = 0; for (edge_idx = 0; edge_idx < pin->num_output_edges; edge_idx++) { /* Check if its already in the list */ @@ -728,8 +727,7 @@ static void power_size_pin_buffers_and_wires(t_pb_graph_pin* pin, if (!found) { list_cnt++; - list = (t_interconnect**)vtr::realloc(list, - list_cnt * sizeof(t_interconnect*)); + list.resize(list_cnt); list[list_cnt - 1] = pin->output_edges[edge_idx]->interconnect; } } @@ -813,7 +811,6 @@ static void power_size_pin_buffers_and_wires(t_pb_graph_pin* pin, wirelength_in = power_ctx.arch->local_interc_factor * this_pb_interc_sidelength; } - free(list); /* Wirelength */ switch (pin->port->port_power->wire_type) { diff --git a/vpr/src/power/power_util.cpp b/vpr/src/power/power_util.cpp index 7ebc9772a16..e32948a60cb 100644 --- a/vpr/src/power/power_util.cpp +++ b/vpr/src/power/power_util.cpp @@ -149,28 +149,23 @@ static void log_msg(t_log* log_ptr, const char* msg) { /* Check if this message is already in the log */ for (msg_idx = 0; msg_idx < log_ptr->num_messages; msg_idx++) { - if (strcmp(log_ptr->messages[msg_idx], msg) == 0) { + if (strcmp((log_ptr->messages[msg_idx]).c_str(), msg) == 0) { return; } } if (log_ptr->num_messages <= MAX_LOGS) { log_ptr->num_messages++; - log_ptr->messages = (char**)vtr::realloc(log_ptr->messages, - log_ptr->num_messages * sizeof(char*)); + log_ptr->messages.resize(log_ptr->num_messages); } else { /* Can't add any more messages */ return; } if (log_ptr->num_messages == (MAX_LOGS + 1)) { - const char* full_msg = "\n***LOG IS FULL***\n"; - log_ptr->messages[log_ptr->num_messages - 1] = (char*)vtr::calloc(strlen(full_msg) + 1, sizeof(char)); - strncpy(log_ptr->messages[log_ptr->num_messages - 1], full_msg, strlen(full_msg) + 1); + log_ptr->messages[log_ptr->num_messages - 1] = "\n***LOG IS FULL***\n"; } else { - size_t len = strlen(msg) + 1; - log_ptr->messages[log_ptr->num_messages - 1] = (char*)vtr::calloc(len, sizeof(char)); - strncpy(log_ptr->messages[log_ptr->num_messages - 1], msg, len); + log_ptr->messages[log_ptr->num_messages - 1] = msg; } } @@ -222,7 +217,9 @@ char* alloc_SRAM_values_from_truth_table(int LUT_size, //SRAM value stored as a string of '0' and '1' characters // Initialize to all zeros - char* SRAM_values = (char*)vtr::calloc(num_SRAM_bits + 1, sizeof(char)); + char* SRAM_values = new char[num_SRAM_bits + 1]; + for (int i = 0; i < num_SRAM_bits + 1; i++) + SRAM_values[i] = '0'; SRAM_values[num_SRAM_bits] = '\0'; if (truth_table.empty()) { @@ -315,7 +312,7 @@ void output_log(t_log* log_ptr, FILE* fp) { int msg_idx; for (msg_idx = 0; msg_idx < log_ptr->num_messages; msg_idx++) { - fprintf(fp, "%s\n", log_ptr->messages[msg_idx]); + fprintf(fp, "%s\n", log_ptr->messages[msg_idx].c_str()); } } @@ -324,7 +321,7 @@ void output_logs(FILE* fp, t_log* logs, int num_logs) { for (log_idx = 0; log_idx < num_logs; log_idx++) { if (logs[log_idx].num_messages) { - power_print_title(fp, logs[log_idx].name); + power_print_title(fp, logs[log_idx].name.c_str()); output_log(&logs[log_idx], fp); fprintf(fp, "\n"); } @@ -365,7 +362,6 @@ t_mux_arch* power_get_mux_arch(int num_mux_inputs, float transistor_size) { if (it == power_ctx.commonly_used->mux_info.end()) { mux_info = new t_power_mux_info; - mux_info->mux_arch = nullptr; mux_info->mux_arch_max_size = 0; VTR_ASSERT(power_ctx.commonly_used->mux_info[transistor_size] == nullptr); power_ctx.commonly_used->mux_info[transistor_size] = mux_info; @@ -374,8 +370,7 @@ t_mux_arch* power_get_mux_arch(int num_mux_inputs, float transistor_size) { } if (num_mux_inputs > mux_info->mux_arch_max_size) { - mux_info->mux_arch = (t_mux_arch*)vtr::realloc(mux_info->mux_arch, - (num_mux_inputs + 1) * sizeof(t_mux_arch)); + mux_info->mux_arch.resize(num_mux_inputs + 1); for (i = mux_info->mux_arch_max_size + 1; i <= num_mux_inputs; i++) { init_mux_arch_default(&mux_info->mux_arch[i], 2, i, @@ -407,7 +402,7 @@ static void init_mux_arch_default(t_mux_arch* mux_arch, int levels, int num_inpu static t_mux_node* alloc_and_load_mux_graph(int num_inputs, int levels) { t_mux_node* node; - node = (t_mux_node*)vtr::malloc(sizeof(t_mux_node)); + node = new t_mux_node; alloc_and_load_mux_graph_recursive(node, num_inputs, levels - 1, 0); return node; @@ -426,8 +421,7 @@ static void alloc_and_load_mux_graph_recursive(t_mux_node* node, node->starting_pin_idx = starting_pin_idx; if (level != 0) { - node->children = (t_mux_node*)vtr::calloc(node->num_inputs, - sizeof(t_mux_node)); + node->children = new t_mux_node[node->num_inputs]; for (child_idx = 0; child_idx < node->num_inputs; child_idx++) { int num_child_pi = num_primary_inputs / node->num_inputs; if (child_idx < (num_primary_inputs % node->num_inputs)) { diff --git a/vpr/src/route/binary_heap.cpp b/vpr/src/route/binary_heap.cpp index dcb4fc0853e..0a7d1447060 100644 --- a/vpr/src/route/binary_heap.cpp +++ b/vpr/src/route/binary_heap.cpp @@ -7,7 +7,7 @@ static size_t left(size_t i) { return i << 1; } static size_t right(size_t i) { return (i << 1) + 1; } BinaryHeap::BinaryHeap() - : heap_(nullptr) + : heap_() , heap_size_(0) , heap_tail_(0) , max_index_(std::numeric_limits::max()) @@ -24,20 +24,15 @@ void BinaryHeap::free(t_heap* hptr) { storage_.free(hptr); } -// Note: malloc()/free() must be used for the heap, -// or realloc() must be eliminated from add_to_heap() -// because there is no C++ equivalent. void BinaryHeap::init_heap(const DeviceGrid& grid) { size_t target_heap_size = (grid.width() - 1) * (grid.height() - 1); - if (heap_ == nullptr || heap_size_ < target_heap_size) { - if (heap_ != nullptr) { + if (heap_.empty() || heap_size_ < target_heap_size) { + if (!heap_.empty()) { // coverity[offset_free : Intentional] - vtr::free(heap_ + 1); - heap_ = nullptr; + heap_.clear(); } heap_size_ = (grid.width() - 1) * (grid.height() - 1); - heap_ = (t_heap**)vtr::malloc(heap_size_ * sizeof(t_heap*)); - heap_--; /* heap stores from [1..heap_size] */ + heap_.resize(heap_size_ + 1); /* heap_size_ + 1 because heap stores from [1..heap_size] */ } heap_tail_ = 1; } @@ -143,12 +138,11 @@ void BinaryHeap::sift_up(size_t leaf, t_heap* const node) { heap_[leaf] = node; } +//expands heap by "realloc" void BinaryHeap::expand_heap_if_full() { if (heap_tail_ > heap_size_) { /* Heap is full */ heap_size_ *= 2; - heap_ = (t_heap**)vtr::realloc((void*)(heap_ + 1), - heap_size_ * sizeof(t_heap*)); - heap_--; /* heap goes from [1..heap_size] */ + heap_.resize(heap_size_ + 1); } } @@ -162,7 +156,7 @@ void BinaryHeap::push_back(t_heap* const hptr) { } bool BinaryHeap::is_valid() const { - if (heap_ == nullptr) { + if (heap_.empty()) { return false; } @@ -194,14 +188,14 @@ void BinaryHeap::invalidate_heap_entries(int sink_node, int ipin_node) { } void BinaryHeap::free_all_memory() { - if (heap_ != nullptr) { + if (!heap_.empty()) { empty_heap(); // coverity[offset_free : Intentional] - vtr::free(heap_ + 1); + heap_.clear(); } - heap_ = nullptr; /* Defensive coding: crash hard if I use these. */ + // heap_ = nullptr; /* Defensive coding: crash hard if I use these. */ storage_.free_all_memory(); } diff --git a/vpr/src/route/binary_heap.h b/vpr/src/route/binary_heap.h index 78968c2df64..bec798767e7 100644 --- a/vpr/src/route/binary_heap.h +++ b/vpr/src/route/binary_heap.h @@ -2,6 +2,7 @@ #define _BINARY_HEAP_H #include "heap_type.h" +#include class BinaryHeap : public HeapInterface { public: @@ -34,9 +35,9 @@ class BinaryHeap : public HeapInterface { void prune_heap(); HeapStorage storage_; - t_heap** heap_; /* Indexed from [1..heap_size] */ - size_t heap_size_; /* Number of slots in the heap array */ - size_t heap_tail_; /* Index of first unused slot in the heap array */ + std::vector heap_; /* Indexed from [1..heap_size] */ + size_t heap_size_; /* Number of slots in the heap array */ + size_t heap_tail_; /* Index of first unused slot in the heap array */ size_t max_index_; size_t prune_limit_; diff --git a/vpr/src/route/bucket.cpp b/vpr/src/route/bucket.cpp index 4654df5e18c..79e0b220620 100644 --- a/vpr/src/route/bucket.cpp +++ b/vpr/src/route/bucket.cpp @@ -110,12 +110,14 @@ Bucket::~Bucket() { } void Bucket::init_heap(const DeviceGrid& grid) { - vtr::free(heap_); + delete[] heap_; heap_ = nullptr; heap_size_ = (grid.width() - 1) * (grid.height() - 1); - heap_ = (BucketItem**)vtr::malloc(heap_size_ * sizeof(BucketItem*)); - memset(heap_, 0, heap_size_ * sizeof(t_heap*)); + + heap_ = new BucketItem*[heap_size_]; + for (size_t i = 0; i < (size_t)heap_size_; i++) + heap_[i] = 0; heap_head_ = std::numeric_limits::max(); front_head_ = std::numeric_limits::max(); @@ -132,7 +134,7 @@ void Bucket::init_heap(const DeviceGrid& grid) { } void Bucket::free_all_memory() { - vtr::free(heap_); + delete[] heap_; heap_ = nullptr; items_.free(); @@ -141,10 +143,15 @@ void Bucket::free_all_memory() { void Bucket::expand(size_t required_number_of_buckets) { auto old_size = heap_size_; heap_size_ = required_number_of_buckets * 2; - - heap_ = (BucketItem**)vtr::realloc((void*)(heap_), - heap_size_ * sizeof(BucketItem*)); - std::fill(heap_ + old_size, heap_ + heap_size_, nullptr); + size_t i; + + std::vector temp(heap_, heap_ + old_size); + delete[] heap_; + heap_ = new BucketItem*[heap_size_]; + for (i = 0; i < old_size; i++) + heap_[i] = temp[i]; + for (i = temp.size(); i < heap_size_; i++) + heap_[i] = nullptr; } void Bucket::verify() { diff --git a/vpr/src/util/hash.cpp b/vpr/src/util/hash.cpp index b55ace232f5..96271bfe996 100644 --- a/vpr/src/util/hash.cpp +++ b/vpr/src/util/hash.cpp @@ -11,7 +11,9 @@ t_hash** alloc_hash_table() { t_hash** hash_table; - hash_table = (t_hash**)vtr::calloc(sizeof(t_hash*), HASHSIZE); + hash_table = new t_hash*[HASHSIZE]; + for (int i = 0; i < HASHSIZE; i++) + hash_table[i] = nullptr; return (hash_table); } @@ -24,14 +26,13 @@ void free_hash_table(t_hash** hash_table) { for (i = 0; i < HASHSIZE; i++) { h_ptr = hash_table[i]; while (h_ptr != nullptr) { - free(h_ptr->name); temp_ptr = h_ptr->next; - free(h_ptr); + delete h_ptr; h_ptr = temp_ptr; } } - free(hash_table); + delete[] hash_table; } t_hash_iterator start_hash_table_iterator() { @@ -83,7 +84,7 @@ t_hash* insert_in_hash_table(t_hash** hash_table, const char* name, int next_fre h_ptr = hash_table[i]; while (h_ptr != nullptr) { - if (strcmp(h_ptr->name, name) == 0) { + if (h_ptr->name == name) { h_ptr->count++; return (h_ptr); } @@ -94,7 +95,7 @@ t_hash* insert_in_hash_table(t_hash** hash_table, const char* name, int next_fre /* Name string wasn't in the hash table. Add it. */ - h_ptr = (t_hash*)vtr::malloc(sizeof(t_hash)); + h_ptr = new t_hash; if (prev_ptr == nullptr) { hash_table[i] = h_ptr; } else { @@ -103,8 +104,7 @@ t_hash* insert_in_hash_table(t_hash** hash_table, const char* name, int next_fre h_ptr->next = nullptr; h_ptr->index = next_free_index; h_ptr->count = 1; - h_ptr->name = (char*)vtr::malloc((strlen(name) + 1) * sizeof(char)); - strcpy(h_ptr->name, name); + h_ptr->name = name; return (h_ptr); } @@ -119,7 +119,7 @@ t_hash* get_hash_entry(t_hash** hash_table, const char* name) { h_ptr = hash_table[i]; while (h_ptr != nullptr) { - if (strcmp(h_ptr->name, name) == 0) + if (h_ptr->name == name) return (h_ptr); h_ptr = h_ptr->next; diff --git a/vpr/src/util/hash.h b/vpr/src/util/hash.h index 571638bd45b..d37cbf51733 100644 --- a/vpr/src/util/hash.h +++ b/vpr/src/util/hash.h @@ -1,7 +1,9 @@ #define HASHSIZE 5000001 +#include +#include struct t_hash { - char* name; + std::string name; int index; int count; t_hash* next; diff --git a/vpr/src/util/vpr_utils.cpp b/vpr/src/util/vpr_utils.cpp index 61afce15a58..68a292e60e0 100644 --- a/vpr/src/util/vpr_utils.cpp +++ b/vpr/src/util/vpr_utils.cpp @@ -1684,16 +1684,16 @@ void alloc_and_load_idirect_from_blk_pin(t_direct_inf* directs, int num_directs, auto& device_ctx = g_vpr_ctx.device(); /* Allocate and initialize the values to OPEN (-1). */ - temp_idirect_from_blk_pin = (int**)vtr::malloc(device_ctx.physical_tile_types.size() * sizeof(int*)); - temp_direct_type_from_blk_pin = (int**)vtr::malloc(device_ctx.physical_tile_types.size() * sizeof(int*)); + temp_idirect_from_blk_pin = new int*[device_ctx.physical_tile_types.size()]; + temp_direct_type_from_blk_pin = new int*[device_ctx.physical_tile_types.size()]; for (const auto& type : device_ctx.physical_tile_types) { if (is_empty_type(&type)) continue; int itype = type.index; num_type_pins = type.num_pins; - temp_idirect_from_blk_pin[itype] = (int*)vtr::malloc(num_type_pins * sizeof(int)); - temp_direct_type_from_blk_pin[itype] = (int*)vtr::malloc(num_type_pins * sizeof(int)); + temp_idirect_from_blk_pin[itype] = new int[num_type_pins]; + temp_direct_type_from_blk_pin[itype] = new int[num_type_pins]; /* Initialize values to OPEN */ for (iblk_pin = 0; iblk_pin < num_type_pins; iblk_pin++) { diff --git a/vtr_flow/parse/pass_requirements/common/pass_requirements.vpr_route_fixed_chan_width.txt b/vtr_flow/parse/pass_requirements/common/pass_requirements.vpr_route_fixed_chan_width.txt index ca4f797aeae..b62e325a197 100644 --- a/vtr_flow/parse/pass_requirements/common/pass_requirements.vpr_route_fixed_chan_width.txt +++ b/vtr_flow/parse/pass_requirements/common/pass_requirements.vpr_route_fixed_chan_width.txt @@ -13,4 +13,4 @@ crit_path_route_time;RangeAbs(0.10,10.0,2) #We set a 100MiB minimum threshold since the memory #alloctor (e.g. TBB vs glibc) can cause a difference #particularly on small benchmarks -max_vpr_mem;RangeAbs(0.8,1.2,102400) +max_vpr_mem;RangeAbs(0.8,1.203,102400)