-void proc_cloning(float threshold)
-{
- entry_t *entry = NULL, *p;
- ir_graph *irg;
- int i;
- q_set hmap;
-
- obstack_init(&hmap.obst);
- hmap.map = NULL;
- hmap.heavy_uses = NULL;
-
- /* initially fill our map by visiting all irgs */
- for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
- irg = get_irp_irg(i);
- irg_walk_graph(irg, collect_irg_calls, NULL, &hmap);
- }
-
- /* We have the "Call" nodes to optimize in set "set_entries". Our algorithm
- replace one constant parameter and make a new "Call" node for all found "Calls". It exchange the
- old one with the new one and the algorithm is called with the new "Call".
- */
- while (hmap.map || hmap.heavy_uses) {
- /* We iterate the set and arrange the element of the set in a list.
- The elements are arranged dependent of their value descending.*/
- if (hmap.map) {
- for (entry = pset_first(hmap.map); entry; entry = pset_next(hmap.map)) {
- entry->weight = calculate_weight(entry);
-
- /*
- * Do not put entry with a weight < threshold in the list
- */
- if (entry->weight < threshold) {
- kill_entry(entry);
- continue;
- }
-
- /* put entry in the heavy uses list */
- entry->next = NULL;
- if (! hmap.heavy_uses)
- hmap.heavy_uses = entry;
- else {
- if (entry->weight >= hmap.heavy_uses->weight) {
- entry->next = hmap.heavy_uses;
- hmap.heavy_uses = entry;
- }
- else {
- for (p = hmap.heavy_uses; p->next; p = p->next) {
- if (entry->weight >= p->next->weight) {
- entry->next = p->next;
- p->next = entry;
- break;
- }
- }
- if (! p->next)
- p->next = entry;
- }
- }
- }
- del_pset(hmap.map);
- hmap.map = NULL;
- }
-
- /* Print some information about the list. */
- printf("-----------------\n");
- for (entry = hmap.heavy_uses; entry; entry = entry->next) {
- printf("\nweight: is %f\n", entry->weight);
- ir_printf("Call for Method %E\n", entry->q.ent);
- printf("Position %i\n", entry->q.pos);
- ir_printf("Value %T\n", entry->q.tv);
- }
-
- entry = hmap.heavy_uses;
- if (entry) {
- entity *ent = clone_method(&entry->q);
-
- hmap.heavy_uses = entry->next;
-
- /* We must exchange the copies of this call in all clones too.*/
- exchange_calls(&entry->q, ent);
- kill_entry(entry);
-
- /*
- * after we exchanged all calls, some entries on the list for
- * the next cloned entity may get invalid, so we have to check
- * them and may even update the list of heavy uses.
- */
- reorder_weights(&hmap, threshold);
- }
- }
- obstack_free(&hmap.obst, NULL);
+void proc_cloning(float threshold) {
+ entry_t *entry = NULL, *p;
+ ir_graph *irg;
+ int i;
+ q_set hmap;
+
+ obstack_init(&hmap.obst);
+ hmap.map = NULL;
+ hmap.heavy_uses = NULL;
+
+ /* initially fill our map by visiting all irgs */
+ for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
+ irg = get_irp_irg(i);
+ irg_walk_graph(irg, collect_irg_calls, NULL, &hmap);
+ }
+
+ /* We have the "Call" nodes to optimize in set "set_entries". Our algorithm
+ replace one constant parameter and make a new "Call" node for all found "Calls". It exchange the
+ old one with the new one and the algorithm is called with the new "Call".
+ */
+ while (hmap.map || hmap.heavy_uses) {
+ /* We iterate the set and arrange the element of the set in a list.
+ The elements are arranged dependent of their value descending.*/
+ if (hmap.map) {
+ foreach_pset(hmap.map, entry) {
+ entry->weight = calculate_weight(entry);
+
+ /*
+ * Do not put entry with a weight < threshold in the list
+ */
+ if (entry->weight < threshold) {
+ kill_entry(entry);
+ continue;
+ }
+
+ /* put entry in the heavy uses list */
+ entry->next = NULL;
+ if (! hmap.heavy_uses)
+ hmap.heavy_uses = entry;
+ else {
+ if (entry->weight >= hmap.heavy_uses->weight) {
+ entry->next = hmap.heavy_uses;
+ hmap.heavy_uses = entry;
+ } else {
+ for (p = hmap.heavy_uses; p->next; p = p->next) {
+ if (entry->weight >= p->next->weight) {
+ entry->next = p->next;
+ p->next = entry;
+ break;
+ }
+ }
+ if (! p->next)
+ p->next = entry;
+ }
+ }
+ }
+ del_pset(hmap.map);
+ hmap.map = NULL;
+ }
+
+ /* Print some information about the list. */
+ printf("-----------------\n");
+ for (entry = hmap.heavy_uses; entry; entry = entry->next) {
+ printf("\nweight: is %f\n", entry->weight);
+ ir_printf("Call for Method %E\n", entry->q.ent);
+ printf("Position %i\n", entry->q.pos);
+ ir_printf("Value %T\n", entry->q.tv);
+ }
+
+ entry = hmap.heavy_uses;
+ if (entry) {
+ ir_entity *ent = clone_method(&entry->q);
+
+ hmap.heavy_uses = entry->next;
+
+ /* We must exchange the copies of this call in all clones too.*/
+ exchange_calls(&entry->q, ent);
+ kill_entry(entry);
+
+ /*
+ * after we exchanged all calls, some entries on the list for
+ * the next cloned entity may get invalid, so we have to check
+ * them and may even update the list of heavy uses.
+ */
+ reorder_weights(&hmap, threshold);
+ }
+ }
+ obstack_free(&hmap.obst, NULL);