-
Notifications
You must be signed in to change notification settings - Fork 415
Eliminate vtr_free and vtr_malloc/vtr_calloc/vtr_realloc #3040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
efd922c
2f679a7
0bdb49f
7cb2095
2c12600
c0bf94c
e7b470a
e8875c7
3256475
d04d41f
81eba83
700cc75
ba39dae
d0c4cb9
1193d3b
6eb6a8f
c658a87
faa099d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,7 +163,7 @@ void free_arch(t_arch* arch) { | |
vtr::free(arch->architecture_id); | ||
|
||
if (arch->clocks) { | ||
vtr::free(arch->clocks->clock_inf); | ||
delete[] arch->clocks->clock_inf; | ||
} | ||
|
||
delete (arch->noc); | ||
|
@@ -335,17 +335,17 @@ static void free_pb_type(t_pb_type* pb_type) { | |
for (int m = 0; m < pb_type->modes[i].interconnect[j].annotations[k].num_value_prop_pairs; ++m) { | ||
vtr::free(pb_type->modes[i].interconnect[j].annotations[k].value[m]); | ||
} | ||
vtr::free(pb_type->modes[i].interconnect[j].annotations[k].prop); | ||
vtr::free(pb_type->modes[i].interconnect[j].annotations[k].value); | ||
delete[] pb_type->modes[i].interconnect[j].annotations[k].prop; | ||
delete[] pb_type->modes[i].interconnect[j].annotations[k].value; | ||
SamuelHo10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
vtr::free(pb_type->modes[i].interconnect[j].annotations); | ||
delete[] pb_type->modes[i].interconnect[j].annotations; | ||
if (pb_type->modes[i].interconnect[j].interconnect_power) | ||
vtr::free(pb_type->modes[i].interconnect[j].interconnect_power); | ||
delete pb_type->modes[i].interconnect[j].interconnect_power; | ||
} | ||
if (pb_type->modes[i].interconnect) | ||
delete[] pb_type->modes[i].interconnect; | ||
if (pb_type->modes[i].mode_power) | ||
vtr::free(pb_type->modes[i].mode_power); | ||
delete (pb_type->modes[i].mode_power); | ||
} | ||
if (pb_type->modes) | ||
delete[] pb_type->modes; | ||
|
@@ -354,8 +354,8 @@ static void free_pb_type(t_pb_type* pb_type) { | |
for (int j = 0; j < pb_type->annotations[i].num_value_prop_pairs; ++j) { | ||
vtr::free(pb_type->annotations[i].value[j]); | ||
} | ||
vtr::free(pb_type->annotations[i].value); | ||
vtr::free(pb_type->annotations[i].prop); | ||
delete[] pb_type->annotations[i].value; | ||
delete[] pb_type->annotations[i].prop; | ||
if (pb_type->annotations[i].input_pins) { | ||
vtr::free(pb_type->annotations[i].input_pins); | ||
} | ||
|
@@ -371,7 +371,7 @@ static void free_pb_type(t_pb_type* pb_type) { | |
} | ||
|
||
if (pb_type->pb_type_power) { | ||
vtr::free(pb_type->pb_type_power); | ||
delete pb_type->pb_type_power; | ||
} | ||
|
||
for (int i = 0; i < pb_type->num_ports; ++i) { | ||
|
@@ -380,10 +380,10 @@ static void free_pb_type(t_pb_type* pb_type) { | |
vtr::free(pb_type->ports[i].port_class); | ||
} | ||
if (pb_type->ports[i].port_power) { | ||
vtr::free(pb_type->ports[i].port_power); | ||
delete pb_type->ports[i].port_power; | ||
} | ||
} | ||
vtr::free(pb_type->ports); | ||
delete[] pb_type->ports; | ||
} | ||
|
||
t_port* findPortByName(const char* name, t_pb_type* pb_type, int* high_index, int* low_index) { | ||
|
@@ -495,13 +495,12 @@ void alloc_and_load_default_child_for_pb_type(t_pb_type* pb_type, | |
copy->num_pb = 1; | ||
|
||
/* Power */ | ||
copy->pb_type_power = (t_pb_type_power*)vtr::calloc(1, | ||
sizeof(t_pb_type_power)); | ||
copy->pb_type_power = new t_pb_type_power(); | ||
SamuelHo10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
copy->pb_type_power->estimation_method = power_method_inherited(pb_type->pb_type_power->estimation_method); | ||
|
||
/* Ports */ | ||
copy->num_ports = pb_type->num_ports; | ||
copy->ports = (t_port*)vtr::calloc(pb_type->num_ports, sizeof(t_port)); | ||
copy->ports = new t_port[pb_type->num_ports](); | ||
SamuelHo10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (i = 0; i < pb_type->num_ports; i++) { | ||
copy->ports[i].is_clock = pb_type->ports[i].is_clock; | ||
copy->ports[i].model_port = pb_type->ports[i].model_port; | ||
|
@@ -514,8 +513,7 @@ void alloc_and_load_default_child_for_pb_type(t_pb_type* pb_type, | |
copy->ports[i].index = pb_type->ports[i].index; | ||
copy->ports[i].absolute_first_pin_index = pb_type->ports[i].absolute_first_pin_index; | ||
|
||
copy->ports[i].port_power = (t_port_power*)vtr::calloc(1, | ||
sizeof(t_port_power)); | ||
copy->ports[i].port_power = new t_port_power(); | ||
SamuelHo10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//Defaults | ||
if (copy->pb_type_power->estimation_method == POWER_METHOD_AUTO_SIZES) { | ||
copy->ports[i].port_power->wire_type = POWER_WIRE_TYPE_AUTO; | ||
|
@@ -549,8 +547,8 @@ void alloc_and_load_default_child_for_pb_type(t_pb_type* pb_type, | |
copy->annotations[i].format = pb_type->annotations[i].format; | ||
copy->annotations[i].type = pb_type->annotations[i].type; | ||
copy->annotations[i].num_value_prop_pairs = pb_type->annotations[i].num_value_prop_pairs; | ||
copy->annotations[i].prop = (int*)vtr::malloc(sizeof(int) * pb_type->annotations[i].num_value_prop_pairs); | ||
copy->annotations[i].value = (char**)vtr::malloc(sizeof(char*) * pb_type->annotations[i].num_value_prop_pairs); | ||
copy->annotations[i].prop = new int[pb_type->annotations[i].num_value_prop_pairs]; | ||
copy->annotations[i].value = new char*[pb_type->annotations[i].num_value_prop_pairs]; | ||
SamuelHo10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (j = 0; j < pb_type->annotations[i].num_value_prop_pairs; j++) { | ||
copy->annotations[i].prop[j] = pb_type->annotations[i].prop[j]; | ||
copy->annotations[i].value[j] = vtr::strdup(pb_type->annotations[i].value[j]); | ||
|
@@ -580,8 +578,7 @@ void ProcessLutClass(t_pb_type* lut_pb_type) { | |
lut_pb_type->modes[0].parent_pb_type = lut_pb_type; | ||
lut_pb_type->modes[0].index = 0; | ||
lut_pb_type->modes[0].num_pb_type_children = 0; | ||
lut_pb_type->modes[0].mode_power = (t_mode_power*)vtr::calloc(1, | ||
sizeof(t_mode_power)); | ||
lut_pb_type->modes[0].mode_power = new t_mode_power(); | ||
|
||
/* Process interconnect */ | ||
/* TODO: add timing annotations to route-through */ | ||
|
@@ -613,10 +610,9 @@ void ProcessLutClass(t_pb_type* lut_pb_type) { | |
|
||
lut_pb_type->modes[0].interconnect[0].parent_mode_index = 0; | ||
lut_pb_type->modes[0].interconnect[0].parent_mode = &lut_pb_type->modes[0]; | ||
lut_pb_type->modes[0].interconnect[0].interconnect_power = (t_interconnect_power*)vtr::calloc(1, sizeof(t_interconnect_power)); | ||
lut_pb_type->modes[0].interconnect[0].interconnect_power = new t_interconnect_power(); | ||
SamuelHo10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
lut_pb_type->modes[0].interconnect[0].annotations = (t_pin_to_pin_annotation*)vtr::calloc(lut_pb_type->num_annotations, | ||
sizeof(t_pin_to_pin_annotation)); | ||
lut_pb_type->modes[0].interconnect[0].annotations = new t_pin_to_pin_annotation[lut_pb_type->num_annotations](); | ||
SamuelHo10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
lut_pb_type->modes[0].interconnect[0].num_annotations = lut_pb_type->num_annotations; | ||
for (i = 0; i < lut_pb_type->modes[0].interconnect[0].num_annotations; | ||
i++) { | ||
|
@@ -627,10 +623,8 @@ void ProcessLutClass(t_pb_type* lut_pb_type) { | |
lut_pb_type->modes[0].interconnect[0].annotations[i].format = lut_pb_type->annotations[i].format; | ||
lut_pb_type->modes[0].interconnect[0].annotations[i].type = lut_pb_type->annotations[i].type; | ||
lut_pb_type->modes[0].interconnect[0].annotations[i].num_value_prop_pairs = lut_pb_type->annotations[i].num_value_prop_pairs; | ||
lut_pb_type->modes[0].interconnect[0].annotations[i].prop = (int*)vtr::malloc(sizeof(int) | ||
* lut_pb_type->annotations[i].num_value_prop_pairs); | ||
lut_pb_type->modes[0].interconnect[0].annotations[i].value = (char**)vtr::malloc(sizeof(char*) | ||
* lut_pb_type->annotations[i].num_value_prop_pairs); | ||
lut_pb_type->modes[0].interconnect[0].annotations[i].prop = new int[lut_pb_type->annotations[i].num_value_prop_pairs]; | ||
lut_pb_type->modes[0].interconnect[0].annotations[i].value = new char*[lut_pb_type->annotations[i].num_value_prop_pairs]; | ||
for (j = 0; j < lut_pb_type->annotations[i].num_value_prop_pairs; j++) { | ||
lut_pb_type->modes[0].interconnect[0].annotations[i].prop[j] = lut_pb_type->annotations[i].prop[j]; | ||
lut_pb_type->modes[0].interconnect[0].annotations[i].value[j] = vtr::strdup(lut_pb_type->annotations[i].value[j]); | ||
|
@@ -643,30 +637,29 @@ void ProcessLutClass(t_pb_type* lut_pb_type) { | |
lut_pb_type->modes[1].parent_pb_type = lut_pb_type; | ||
lut_pb_type->modes[1].index = 1; | ||
lut_pb_type->modes[1].num_pb_type_children = 1; | ||
lut_pb_type->modes[1].mode_power = (t_mode_power*)vtr::calloc(1, | ||
sizeof(t_mode_power)); | ||
lut_pb_type->modes[1].mode_power = new t_mode_power(); | ||
lut_pb_type->modes[1].pb_type_children = new t_pb_type[1]; | ||
alloc_and_load_default_child_for_pb_type(lut_pb_type, default_name, | ||
lut_pb_type->modes[1].pb_type_children); | ||
/* moved annotations to child so delete old annotations */ | ||
for (i = 0; i < lut_pb_type->num_annotations; i++) { | ||
for (j = 0; j < lut_pb_type->annotations[i].num_value_prop_pairs; j++) { | ||
free(lut_pb_type->annotations[i].value[j]); | ||
vtr::free(lut_pb_type->annotations[i].value[j]); | ||
} | ||
free(lut_pb_type->annotations[i].value); | ||
free(lut_pb_type->annotations[i].prop); | ||
delete[] lut_pb_type->annotations[i].value; | ||
delete[] lut_pb_type->annotations[i].prop; | ||
if (lut_pb_type->annotations[i].input_pins) { | ||
free(lut_pb_type->annotations[i].input_pins); | ||
vtr::free(lut_pb_type->annotations[i].input_pins); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly we could convert these C-strings to std::string so we don't need free calls for them, but it depends on how many places they are used (how much code you have to go change to use C++ strings) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for .output_pins and .clock There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do that in another PR |
||
} | ||
if (lut_pb_type->annotations[i].output_pins) { | ||
free(lut_pb_type->annotations[i].output_pins); | ||
vtr::free(lut_pb_type->annotations[i].output_pins); | ||
} | ||
if (lut_pb_type->annotations[i].clock) { | ||
free(lut_pb_type->annotations[i].clock); | ||
vtr::free(lut_pb_type->annotations[i].clock); | ||
} | ||
} | ||
lut_pb_type->num_annotations = 0; | ||
free(lut_pb_type->annotations); | ||
vtr::free(lut_pb_type->annotations); | ||
lut_pb_type->annotations = nullptr; | ||
lut_pb_type->modes[1].pb_type_children[0].depth = lut_pb_type->depth + 1; | ||
lut_pb_type->modes[1].pb_type_children[0].parent_mode = &lut_pb_type->modes[1]; | ||
|
@@ -694,7 +687,7 @@ void ProcessLutClass(t_pb_type* lut_pb_type) { | |
|
||
lut_pb_type->modes[1].interconnect[0].parent_mode_index = 1; | ||
lut_pb_type->modes[1].interconnect[0].parent_mode = &lut_pb_type->modes[1]; | ||
lut_pb_type->modes[1].interconnect[0].interconnect_power = (t_interconnect_power*)vtr::calloc(1, sizeof(t_interconnect_power)); | ||
lut_pb_type->modes[1].interconnect[0].interconnect_power = new t_interconnect_power(); | ||
|
||
lut_pb_type->modes[1].interconnect[1].name = (char*)vtr::calloc(strlen(lut_pb_type->name) + 11, sizeof(char)); | ||
sprintf(lut_pb_type->modes[1].interconnect[1].name, "direct:%s", | ||
|
@@ -713,7 +706,7 @@ void ProcessLutClass(t_pb_type* lut_pb_type) { | |
|
||
lut_pb_type->modes[1].interconnect[1].parent_mode_index = 1; | ||
lut_pb_type->modes[1].interconnect[1].parent_mode = &lut_pb_type->modes[1]; | ||
lut_pb_type->modes[1].interconnect[1].interconnect_power = (t_interconnect_power*)vtr::calloc(1, sizeof(t_interconnect_power)); | ||
lut_pb_type->modes[1].interconnect[1].interconnect_power = new t_interconnect_power(); | ||
|
||
free(default_name); | ||
|
||
|
@@ -738,8 +731,7 @@ void ProcessMemoryClass(t_pb_type* mem_pb_type) { | |
mem_pb_type->modes[0].name = vtr::strdup(default_name); | ||
mem_pb_type->modes[0].parent_pb_type = mem_pb_type; | ||
mem_pb_type->modes[0].index = 0; | ||
mem_pb_type->modes[0].mode_power = (t_mode_power*)vtr::calloc(1, | ||
sizeof(t_mode_power)); | ||
mem_pb_type->modes[0].mode_power = new t_mode_power(); | ||
num_pb = OPEN; | ||
for (i = 0; i < mem_pb_type->num_ports; i++) { | ||
if (mem_pb_type->ports[i].port_class != nullptr | ||
|
@@ -835,8 +827,7 @@ void ProcessMemoryClass(t_pb_type* mem_pb_type) { | |
} | ||
|
||
/* Allocate interconnect power structures */ | ||
mem_pb_type->modes[0].interconnect[i_inter].interconnect_power = (t_interconnect_power*)vtr::calloc(1, | ||
sizeof(t_interconnect_power)); | ||
mem_pb_type->modes[0].interconnect[i_inter].interconnect_power = new t_interconnect_power(); | ||
i_inter++; | ||
} else { | ||
for (j = 0; j < num_pb; j++) { | ||
|
@@ -876,8 +867,7 @@ void ProcessMemoryClass(t_pb_type* mem_pb_type) { | |
} | ||
|
||
/* Allocate interconnect power structures */ | ||
mem_pb_type->modes[0].interconnect[i_inter].interconnect_power = (t_interconnect_power*)vtr::calloc(1, | ||
sizeof(t_interconnect_power)); | ||
mem_pb_type->modes[0].interconnect[i_inter].interconnect_power = new t_interconnect_power(); | ||
i_inter++; | ||
} | ||
} | ||
|
@@ -944,7 +934,7 @@ void SyncModelsPbTypes_rec(t_arch* arch, | |
|
||
pb_type->model_id = model_match_prim_id; | ||
vtr::t_linked_vptr* old = model_match_prim.pb_types; | ||
model_match_prim.pb_types = (vtr::t_linked_vptr*)vtr::malloc(sizeof(vtr::t_linked_vptr)); | ||
model_match_prim.pb_types = new vtr::t_linked_vptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could probably change this linked list (which currently stores pb_type* pointers) to a vector of pb_type* (or maybe even just to direct pb_type elements). Probably don't do that yet though ... we should refactor in stages. |
||
model_match_prim.pb_types->next = old; | ||
model_match_prim.pb_types->data_vptr = pb_type; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.