comparison gcc/tree-outof-ssa.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Convert a program in SSA form into Normal form. 1 /* Convert a program in SSA form into Normal form.
2 Copyright (C) 2004-2017 Free Software Foundation, Inc. 2 Copyright (C) 2004-2018 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
25 #include "rtl.h" 25 #include "rtl.h"
26 #include "tree.h" 26 #include "tree.h"
27 #include "gimple.h" 27 #include "gimple.h"
28 #include "cfghooks.h" 28 #include "cfghooks.h"
29 #include "ssa.h" 29 #include "ssa.h"
30 #include "tree-ssa.h"
30 #include "memmodel.h" 31 #include "memmodel.h"
31 #include "emit-rtl.h" 32 #include "emit-rtl.h"
32 #include "gimple-pretty-print.h" 33 #include "gimple-pretty-print.h"
33 #include "diagnostic-core.h" 34 #include "diagnostic-core.h"
35 #include "tree-dfa.h"
34 #include "stor-layout.h" 36 #include "stor-layout.h"
35 #include "cfgrtl.h" 37 #include "cfgrtl.h"
36 #include "cfganal.h" 38 #include "cfganal.h"
37 #include "tree-eh.h" 39 #include "tree-eh.h"
38 #include "gimple-iterator.h" 40 #include "gimple-iterator.h"
61 /* Only consider modify stmts. */ 63 /* Only consider modify stmts. */
62 if (!is_gimple_assign (stmt)) 64 if (!is_gimple_assign (stmt))
63 return false; 65 return false;
64 66
65 /* If the statement may throw an exception, it cannot be replaced. */ 67 /* If the statement may throw an exception, it cannot be replaced. */
66 if (stmt_could_throw_p (stmt)) 68 if (stmt_could_throw_p (cfun, stmt))
67 return false; 69 return false;
68 70
69 /* Punt if there is more than 1 def. */ 71 /* Punt if there is more than 1 def. */
70 def = SINGLE_SSA_TREE_OPERAND (stmt, SSA_OP_DEF); 72 def = SINGLE_SSA_TREE_OPERAND (stmt, SSA_OP_DEF);
71 if (!def) 73 if (!def)
884 } 886 }
885 } 887 }
886 } 888 }
887 } 889 }
888 } 890 }
891 }
892
893 /* Create a default def for VAR. */
894
895 static void
896 create_default_def (tree var, void *arg ATTRIBUTE_UNUSED)
897 {
898 if (!is_gimple_reg (var))
899 return;
900
901 tree ssa = get_or_create_ssa_default_def (cfun, var);
902 gcc_assert (ssa);
903 }
904
905 /* Call CALLBACK for all PARM_DECLs and RESULT_DECLs for which
906 assign_parms may ask for a default partition. */
907
908 static void
909 for_all_parms (void (*callback)(tree var, void *arg), void *arg)
910 {
911 for (tree var = DECL_ARGUMENTS (current_function_decl); var;
912 var = DECL_CHAIN (var))
913 callback (var, arg);
914 if (!VOID_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl))))
915 callback (DECL_RESULT (current_function_decl), arg);
916 if (cfun->static_chain_decl)
917 callback (cfun->static_chain_decl, arg);
918 }
919
920 /* We need to pass two arguments to set_parm_default_def_partition,
921 but for_all_parms only supports one. Use a pair. */
922
923 typedef std::pair<var_map, bitmap> parm_default_def_partition_arg;
924
925 /* Set in ARG's PARTS bitmap the bit corresponding to the partition in
926 ARG's MAP containing VAR's default def. */
927
928 static void
929 set_parm_default_def_partition (tree var, void *arg_)
930 {
931 parm_default_def_partition_arg *arg = (parm_default_def_partition_arg *)arg_;
932 var_map map = arg->first;
933 bitmap parts = arg->second;
934
935 if (!is_gimple_reg (var))
936 return;
937
938 tree ssa = ssa_default_def (cfun, var);
939 gcc_assert (ssa);
940
941 int version = var_to_partition (map, ssa);
942 gcc_assert (version != NO_PARTITION);
943
944 bool changed = bitmap_set_bit (parts, version);
945 gcc_assert (changed);
946 }
947
948 /* Allocate and return a bitmap that has a bit set for each partition
949 that contains a default def for a parameter. */
950
951 static bitmap
952 get_parm_default_def_partitions (var_map map)
953 {
954 bitmap parm_default_def_parts = BITMAP_ALLOC (NULL);
955
956 parm_default_def_partition_arg
957 arg = std::make_pair (map, parm_default_def_parts);
958
959 for_all_parms (set_parm_default_def_partition, &arg);
960
961 return parm_default_def_parts;
962 }
963
964 /* Allocate and return a bitmap that has a bit set for each partition
965 that contains an undefined value. */
966
967 static bitmap
968 get_undefined_value_partitions (var_map map)
969 {
970 bitmap undefined_value_parts = BITMAP_ALLOC (NULL);
971
972 for (unsigned int i = 1; i < num_ssa_names; i++)
973 {
974 tree var = ssa_name (i);
975 if (var
976 && !virtual_operand_p (var)
977 && !has_zero_uses (var)
978 && ssa_undefined_value_p (var))
979 {
980 const int p = var_to_partition (map, var);
981 if (p != NO_PARTITION)
982 bitmap_set_bit (undefined_value_parts, p);
983 }
984 }
985
986 return undefined_value_parts;
889 } 987 }
890 988
891 /* Given the out-of-ssa info object SA (with prepared partitions) 989 /* Given the out-of-ssa info object SA (with prepared partitions)
892 eliminate all phi nodes in all basic blocks. Afterwards no 990 eliminate all phi nodes in all basic blocks. Afterwards no
893 basic block will have phi nodes anymore and there are possibly 991 basic block will have phi nodes anymore and there are possibly
943 remove_ssa_form (bool perform_ter, struct ssaexpand *sa) 1041 remove_ssa_form (bool perform_ter, struct ssaexpand *sa)
944 { 1042 {
945 bitmap values = NULL; 1043 bitmap values = NULL;
946 var_map map; 1044 var_map map;
947 1045
948 map = coalesce_ssa_name (); 1046 for_all_parms (create_default_def, NULL);
1047 map = init_var_map (num_ssa_names);
1048 coalesce_ssa_name (map);
949 1049
950 /* Return to viewing the variable list as just all reference variables after 1050 /* Return to viewing the variable list as just all reference variables after
951 coalescing has been performed. */ 1051 coalescing has been performed. */
952 partition_view_normal (map); 1052 partition_view_normal (map);
953 1053