Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-ssa-coalesce.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* Coalesce SSA_NAMES together for the out-of-ssa pass. | 1 /* Coalesce SSA_NAMES together for the out-of-ssa pass. |
2 Copyright (C) 2004-2018 Free Software Foundation, Inc. | 2 Copyright (C) 2004-2020 Free Software Foundation, Inc. |
3 Contributed by Andrew MacLeod <amacleod@redhat.com> | 3 Contributed by Andrew MacLeod <amacleod@redhat.com> |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify | 7 GCC is free software; you can redistribute it and/or modify |
133 { | 133 { |
134 coalesce_table_type *list; /* Hash table. */ | 134 coalesce_table_type *list; /* Hash table. */ |
135 coalesce_pair **sorted; /* List when sorted. */ | 135 coalesce_pair **sorted; /* List when sorted. */ |
136 int num_sorted; /* Number in the sorted list. */ | 136 int num_sorted; /* Number in the sorted list. */ |
137 cost_one_pair *cost_one_list;/* Single use coalesces with cost 1. */ | 137 cost_one_pair *cost_one_list;/* Single use coalesces with cost 1. */ |
138 obstack ob; | |
138 }; | 139 }; |
139 | 140 |
140 #define NO_BEST_COALESCE -1 | 141 #define NO_BEST_COALESCE -1 |
141 #define MUST_COALESCE_COST INT_MAX | 142 #define MUST_COALESCE_COST INT_MAX |
142 | 143 |
224 | 225 |
225 *p1 = ptr->first_element; | 226 *p1 = ptr->first_element; |
226 *p2 = ptr->second_element; | 227 *p2 = ptr->second_element; |
227 cl->cost_one_list = ptr->next; | 228 cl->cost_one_list = ptr->next; |
228 | 229 |
229 free (ptr); | |
230 | |
231 return 1; | 230 return 1; |
232 } | 231 } |
233 | 232 |
234 /* Retrieve the most expensive remaining pair to coalesce from CL. Returns the | 233 /* Retrieve the most expensive remaining pair to coalesce from CL. Returns the |
235 2 elements via P1 and P2. Their calculated cost is returned by the function. | 234 2 elements via P1 and P2. Their calculated cost is returned by the function. |
249 | 248 |
250 node = cl->sorted[--(cl->num_sorted)]; | 249 node = cl->sorted[--(cl->num_sorted)]; |
251 *p1 = node->first_element; | 250 *p1 = node->first_element; |
252 *p2 = node->second_element; | 251 *p2 = node->second_element; |
253 ret = node->cost; | 252 ret = node->cost; |
254 free (node); | |
255 | 253 |
256 return ret; | 254 return ret; |
257 } | 255 } |
258 | 256 |
259 | 257 |
271 list = (coalesce_list *) xmalloc (sizeof (struct coalesce_list)); | 269 list = (coalesce_list *) xmalloc (sizeof (struct coalesce_list)); |
272 list->list = new coalesce_table_type (size); | 270 list->list = new coalesce_table_type (size); |
273 list->sorted = NULL; | 271 list->sorted = NULL; |
274 list->num_sorted = 0; | 272 list->num_sorted = 0; |
275 list->cost_one_list = NULL; | 273 list->cost_one_list = NULL; |
274 gcc_obstack_init (&list->ob); | |
276 return list; | 275 return list; |
277 } | 276 } |
278 | 277 |
279 | 278 |
280 /* Delete coalesce list CL. */ | 279 /* Delete coalesce list CL. */ |
285 gcc_assert (cl->cost_one_list == NULL); | 284 gcc_assert (cl->cost_one_list == NULL); |
286 delete cl->list; | 285 delete cl->list; |
287 cl->list = NULL; | 286 cl->list = NULL; |
288 free (cl->sorted); | 287 free (cl->sorted); |
289 gcc_assert (cl->num_sorted == 0); | 288 gcc_assert (cl->num_sorted == 0); |
289 obstack_free (&cl->ob, NULL); | |
290 free (cl); | 290 free (cl); |
291 } | 291 } |
292 | 292 |
293 /* Return the number of unique coalesce pairs in CL. */ | 293 /* Return the number of unique coalesce pairs in CL. */ |
294 | 294 |
326 if (!slot) | 326 if (!slot) |
327 return NULL; | 327 return NULL; |
328 | 328 |
329 if (!*slot) | 329 if (!*slot) |
330 { | 330 { |
331 struct coalesce_pair * pair = XNEW (struct coalesce_pair); | 331 struct coalesce_pair * pair = XOBNEW (&cl->ob, struct coalesce_pair); |
332 gcc_assert (cl->sorted == NULL); | 332 gcc_assert (cl->sorted == NULL); |
333 pair->first_element = p.first_element; | 333 pair->first_element = p.first_element; |
334 pair->second_element = p.second_element; | 334 pair->second_element = p.second_element; |
335 pair->cost = 0; | 335 pair->cost = 0; |
336 pair->index = num_coalesce_pairs (cl); | 336 pair->index = num_coalesce_pairs (cl); |
344 static inline void | 344 static inline void |
345 add_cost_one_coalesce (coalesce_list *cl, int p1, int p2) | 345 add_cost_one_coalesce (coalesce_list *cl, int p1, int p2) |
346 { | 346 { |
347 cost_one_pair *pair; | 347 cost_one_pair *pair; |
348 | 348 |
349 pair = XNEW (cost_one_pair); | 349 pair = XOBNEW (&cl->ob, cost_one_pair); |
350 pair->first_element = p1; | 350 pair->first_element = p1; |
351 pair->second_element = p2; | 351 pair->second_element = p2; |
352 pair->next = cl->cost_one_list; | 352 pair->next = cl->cost_one_list; |
353 cl->cost_one_list = pair; | 353 cl->cost_one_list = pair; |
354 } | 354 } |
672 with the same base variable. | 672 with the same base variable. |
673 The values in LIVE_BASE_PARTITIONS are only valid if the base variable is | 673 The values in LIVE_BASE_PARTITIONS are only valid if the base variable is |
674 marked as being live. This delays clearing of these bitmaps until | 674 marked as being live. This delays clearing of these bitmaps until |
675 they are actually needed again. */ | 675 they are actually needed again. */ |
676 | 676 |
677 struct live_track | 677 class live_track |
678 { | 678 { |
679 public: | |
679 bitmap_obstack obstack; /* A place to allocate our bitmaps. */ | 680 bitmap_obstack obstack; /* A place to allocate our bitmaps. */ |
680 bitmap live_base_var; /* Indicates if a basevar is live. */ | 681 bitmap_head live_base_var; /* Indicates if a basevar is live. */ |
681 bitmap *live_base_partitions; /* Live partitions for each basevar. */ | 682 bitmap_head *live_base_partitions; /* Live partitions for each basevar. */ |
682 var_map map; /* Var_map being used for partition mapping. */ | 683 var_map map; /* Var_map being used for partition mapping. */ |
683 }; | 684 }; |
684 | 685 |
685 | 686 |
686 /* This routine will create a new live track structure based on the partitions | 687 /* This routine will create a new live track structure based on the partitions |
693 int lim, x; | 694 int lim, x; |
694 | 695 |
695 /* Make sure there is a partition view in place. */ | 696 /* Make sure there is a partition view in place. */ |
696 gcc_assert (map->partition_to_base_index != NULL); | 697 gcc_assert (map->partition_to_base_index != NULL); |
697 | 698 |
698 ptr = (live_track *) xmalloc (sizeof (live_track)); | 699 ptr = XNEW (live_track); |
699 ptr->map = map; | 700 ptr->map = map; |
700 lim = num_basevars (map); | 701 lim = num_basevars (map); |
701 bitmap_obstack_initialize (&ptr->obstack); | 702 bitmap_obstack_initialize (&ptr->obstack); |
702 ptr->live_base_partitions = (bitmap *) xmalloc (sizeof (bitmap *) * lim); | 703 ptr->live_base_partitions = XNEWVEC (bitmap_head, lim); |
703 ptr->live_base_var = BITMAP_ALLOC (&ptr->obstack); | 704 bitmap_initialize (&ptr->live_base_var, &ptr->obstack); |
704 for (x = 0; x < lim; x++) | 705 for (x = 0; x < lim; x++) |
705 ptr->live_base_partitions[x] = BITMAP_ALLOC (&ptr->obstack); | 706 bitmap_initialize (&ptr->live_base_partitions[x], &ptr->obstack); |
706 return ptr; | 707 return ptr; |
707 } | 708 } |
708 | 709 |
709 | 710 |
710 /* This routine will free the memory associated with PTR. */ | 711 /* This routine will free the memory associated with PTR. */ |
711 | 712 |
712 static void | 713 static void |
713 delete_live_track (live_track *ptr) | 714 delete_live_track (live_track *ptr) |
714 { | 715 { |
715 bitmap_obstack_release (&ptr->obstack); | 716 bitmap_obstack_release (&ptr->obstack); |
716 free (ptr->live_base_partitions); | 717 XDELETEVEC (ptr->live_base_partitions); |
717 free (ptr); | 718 XDELETE (ptr); |
718 } | 719 } |
719 | 720 |
720 | 721 |
721 /* This function will remove PARTITION from the live list in PTR. */ | 722 /* This function will remove PARTITION from the live list in PTR. */ |
722 | 723 |
724 live_track_remove_partition (live_track *ptr, int partition) | 725 live_track_remove_partition (live_track *ptr, int partition) |
725 { | 726 { |
726 int root; | 727 int root; |
727 | 728 |
728 root = basevar_index (ptr->map, partition); | 729 root = basevar_index (ptr->map, partition); |
729 bitmap_clear_bit (ptr->live_base_partitions[root], partition); | 730 bitmap_clear_bit (&ptr->live_base_partitions[root], partition); |
730 /* If the element list is empty, make the base variable not live either. */ | 731 /* If the element list is empty, make the base variable not live either. */ |
731 if (bitmap_empty_p (ptr->live_base_partitions[root])) | 732 if (bitmap_empty_p (&ptr->live_base_partitions[root])) |
732 bitmap_clear_bit (ptr->live_base_var, root); | 733 bitmap_clear_bit (&ptr->live_base_var, root); |
733 } | 734 } |
734 | 735 |
735 | 736 |
736 /* This function will adds PARTITION to the live list in PTR. */ | 737 /* This function will adds PARTITION to the live list in PTR. */ |
737 | 738 |
741 int root; | 742 int root; |
742 | 743 |
743 root = basevar_index (ptr->map, partition); | 744 root = basevar_index (ptr->map, partition); |
744 /* If this base var wasn't live before, it is now. Clear the element list | 745 /* If this base var wasn't live before, it is now. Clear the element list |
745 since it was delayed until needed. */ | 746 since it was delayed until needed. */ |
746 if (bitmap_set_bit (ptr->live_base_var, root)) | 747 if (bitmap_set_bit (&ptr->live_base_var, root)) |
747 bitmap_clear (ptr->live_base_partitions[root]); | 748 bitmap_clear (&ptr->live_base_partitions[root]); |
748 bitmap_set_bit (ptr->live_base_partitions[root], partition); | 749 bitmap_set_bit (&ptr->live_base_partitions[root], partition); |
749 | 750 |
750 } | 751 } |
751 | 752 |
752 | 753 |
753 /* Clear the live bit for VAR in PTR. */ | 754 /* Clear the live bit for VAR in PTR. */ |
772 | 773 |
773 p = var_to_partition (ptr->map, var); | 774 p = var_to_partition (ptr->map, var); |
774 if (p != NO_PARTITION) | 775 if (p != NO_PARTITION) |
775 { | 776 { |
776 root = basevar_index (ptr->map, p); | 777 root = basevar_index (ptr->map, p); |
777 if (bitmap_bit_p (ptr->live_base_var, root)) | 778 if (bitmap_bit_p (&ptr->live_base_var, root)) |
778 return bitmap_bit_p (ptr->live_base_partitions[root], p); | 779 return bitmap_bit_p (&ptr->live_base_partitions[root], p); |
779 } | 780 } |
780 return false; | 781 return false; |
781 } | 782 } |
782 | 783 |
783 | 784 |
817 /* Clear the liveness bit. */ | 818 /* Clear the liveness bit. */ |
818 live_track_remove_partition (ptr, p); | 819 live_track_remove_partition (ptr, p); |
819 | 820 |
820 /* If the bitmap isn't empty now, conflicts need to be added. */ | 821 /* If the bitmap isn't empty now, conflicts need to be added. */ |
821 root = basevar_index (ptr->map, p); | 822 root = basevar_index (ptr->map, p); |
822 if (bitmap_bit_p (ptr->live_base_var, root)) | 823 if (bitmap_bit_p (&ptr->live_base_var, root)) |
823 { | 824 { |
824 b = ptr->live_base_partitions[root]; | 825 b = &ptr->live_base_partitions[root]; |
825 EXECUTE_IF_SET_IN_BITMAP (b, 0, x, bi) | 826 EXECUTE_IF_SET_IN_BITMAP (b, 0, x, bi) |
826 ssa_conflicts_add (graph, p, x); | 827 ssa_conflicts_add (graph, p, x); |
827 } | 828 } |
828 } | 829 } |
829 | 830 |
848 live_track_clear_base_vars (live_track *ptr) | 849 live_track_clear_base_vars (live_track *ptr) |
849 { | 850 { |
850 /* Simply clear the live base list. Anything marked as live in the element | 851 /* Simply clear the live base list. Anything marked as live in the element |
851 lists will be cleared later if/when the base variable ever comes alive | 852 lists will be cleared later if/when the base variable ever comes alive |
852 again. */ | 853 again. */ |
853 bitmap_clear (ptr->live_base_var); | 854 bitmap_clear (&ptr->live_base_var); |
854 } | 855 } |
855 | 856 |
856 | 857 |
857 /* Build a conflict graph based on LIVEINFO. Any partitions which are in the | 858 /* Build a conflict graph based on LIVEINFO. Any partitions which are in the |
858 partition view of the var_map liveinfo is based on get entries in the | 859 partition view of the var_map liveinfo is based on get entries in the |