Mercurial > hg > CbC > CbC_gcc
comparison gcc/explow.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | 77e2b8dfacca |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
65:65488c3d617d | 67:f6334be47118 |
---|---|
1 /* Subroutines for manipulating rtx's in semantically interesting ways. | 1 /* Subroutines for manipulating rtx's in semantically interesting ways. |
2 Copyright (C) 1987, 1991, 1994, 1995, 1996, 1997, 1998, | 2 Copyright (C) 1987, 1991, 1994, 1995, 1996, 1997, 1998, |
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 | 3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
4 Free Software Foundation, Inc. | 4 Free Software Foundation, Inc. |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
8 GCC is free software; you can redistribute it and/or modify it under | 8 GCC is free software; you can redistribute it and/or modify it under |
22 | 22 |
23 #include "config.h" | 23 #include "config.h" |
24 #include "system.h" | 24 #include "system.h" |
25 #include "coretypes.h" | 25 #include "coretypes.h" |
26 #include "tm.h" | 26 #include "tm.h" |
27 #include "toplev.h" | 27 #include "diagnostic-core.h" |
28 #include "rtl.h" | 28 #include "rtl.h" |
29 #include "tree.h" | 29 #include "tree.h" |
30 #include "tm_p.h" | 30 #include "tm_p.h" |
31 #include "flags.h" | 31 #include "flags.h" |
32 #include "except.h" | 32 #include "except.h" |
33 #include "function.h" | 33 #include "function.h" |
34 #include "expr.h" | 34 #include "expr.h" |
35 #include "optabs.h" | 35 #include "optabs.h" |
36 #include "libfuncs.h" | |
36 #include "hard-reg-set.h" | 37 #include "hard-reg-set.h" |
37 #include "insn-config.h" | 38 #include "insn-config.h" |
38 #include "ggc.h" | 39 #include "ggc.h" |
39 #include "recog.h" | 40 #include "recog.h" |
40 #include "langhooks.h" | 41 #include "langhooks.h" |
41 #include "target.h" | 42 #include "target.h" |
42 #include "output.h" | 43 #include "output.h" |
43 | 44 |
44 static rtx break_out_memory_refs (rtx); | 45 static rtx break_out_memory_refs (rtx); |
45 static void emit_stack_probe (rtx); | |
46 | 46 |
47 | 47 |
48 /* Truncate and perhaps sign-extend C as appropriate for MODE. */ | 48 /* Truncate and perhaps sign-extend C as appropriate for MODE. */ |
49 | 49 |
50 HOST_WIDE_INT | 50 HOST_WIDE_INT |
704 | 704 |
705 sa = BITS_PER_UNIT; | 705 sa = BITS_PER_UNIT; |
706 if (SYMBOL_REF_DECL (s) && DECL_P (SYMBOL_REF_DECL (s))) | 706 if (SYMBOL_REF_DECL (s) && DECL_P (SYMBOL_REF_DECL (s))) |
707 sa = DECL_ALIGN (SYMBOL_REF_DECL (s)); | 707 sa = DECL_ALIGN (SYMBOL_REF_DECL (s)); |
708 | 708 |
709 ca = exact_log2 (INTVAL (c) & -INTVAL (c)) * BITS_PER_UNIT; | 709 if (INTVAL (c) == 0) |
710 | 710 align = sa; |
711 align = MIN (sa, ca); | 711 else |
712 { | |
713 ca = ctz_hwi (INTVAL (c)) * BITS_PER_UNIT; | |
714 align = MIN (sa, ca); | |
715 } | |
712 } | 716 } |
713 | 717 |
714 if (align || (MEM_P (x) && MEM_POINTER (x))) | 718 if (align || (MEM_P (x) && MEM_POINTER (x))) |
715 mark_reg_pointer (temp, align); | 719 mark_reg_pointer (temp, align); |
716 } | 720 } |
908 by this machine. SIZE is the desired size, which need not be constant. */ | 912 by this machine. SIZE is the desired size, which need not be constant. */ |
909 | 913 |
910 static rtx | 914 static rtx |
911 round_push (rtx size) | 915 round_push (rtx size) |
912 { | 916 { |
913 int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; | 917 rtx align_rtx, alignm1_rtx; |
914 | 918 |
915 if (align == 1) | 919 if (!SUPPORTS_STACK_ALIGNMENT |
916 return size; | 920 || crtl->preferred_stack_boundary == MAX_SUPPORTED_STACK_ALIGNMENT) |
917 | 921 { |
918 if (CONST_INT_P (size)) | 922 int align = crtl->preferred_stack_boundary / BITS_PER_UNIT; |
919 { | 923 |
920 HOST_WIDE_INT new_size = (INTVAL (size) + align - 1) / align * align; | 924 if (align == 1) |
921 | 925 return size; |
922 if (INTVAL (size) != new_size) | 926 |
923 size = GEN_INT (new_size); | 927 if (CONST_INT_P (size)) |
928 { | |
929 HOST_WIDE_INT new_size = (INTVAL (size) + align - 1) / align * align; | |
930 | |
931 if (INTVAL (size) != new_size) | |
932 size = GEN_INT (new_size); | |
933 return size; | |
934 } | |
935 | |
936 align_rtx = GEN_INT (align); | |
937 alignm1_rtx = GEN_INT (align - 1); | |
924 } | 938 } |
925 else | 939 else |
926 { | 940 { |
927 /* CEIL_DIV_EXPR needs to worry about the addition overflowing, | 941 /* If crtl->preferred_stack_boundary might still grow, use |
928 but we know it can't. So add ourselves and then do | 942 virtual_preferred_stack_boundary_rtx instead. This will be |
929 TRUNC_DIV_EXPR. */ | 943 substituted by the right value in vregs pass and optimized |
930 size = expand_binop (Pmode, add_optab, size, GEN_INT (align - 1), | 944 during combine. */ |
931 NULL_RTX, 1, OPTAB_LIB_WIDEN); | 945 align_rtx = virtual_preferred_stack_boundary_rtx; |
932 size = expand_divmod (0, TRUNC_DIV_EXPR, Pmode, size, GEN_INT (align), | 946 alignm1_rtx = force_operand (plus_constant (align_rtx, -1), NULL_RTX); |
933 NULL_RTX, 1); | 947 } |
934 size = expand_mult (Pmode, size, GEN_INT (align), NULL_RTX, 1); | 948 |
935 } | 949 /* CEIL_DIV_EXPR needs to worry about the addition overflowing, |
950 but we know it can't. So add ourselves and then do | |
951 TRUNC_DIV_EXPR. */ | |
952 size = expand_binop (Pmode, add_optab, size, alignm1_rtx, | |
953 NULL_RTX, 1, OPTAB_LIB_WIDEN); | |
954 size = expand_divmod (0, TRUNC_DIV_EXPR, Pmode, size, align_rtx, | |
955 NULL_RTX, 1); | |
956 size = expand_mult (Pmode, size, align_rtx, NULL_RTX, 1); | |
936 | 957 |
937 return size; | 958 return size; |
938 } | 959 } |
939 | 960 |
940 /* Save the stack pointer for the purpose in SAVE_LEVEL. PSAVE is a pointer | 961 /* Save the stack pointer for the purpose in SAVE_LEVEL. PSAVE is a pointer |
941 to a previously-created save area. If no save area has been allocated, | 962 to a previously-created save area. If no save area has been allocated, |
942 this function will allocate one. If a save area is specified, it | 963 this function will allocate one. If a save area is specified, it |
943 must be of the proper mode. | 964 must be of the proper mode. */ |
944 | |
945 The insns are emitted after insn AFTER, if nonzero, otherwise the insns | |
946 are emitted at the current position. */ | |
947 | 965 |
948 void | 966 void |
949 emit_stack_save (enum save_level save_level, rtx *psave, rtx after) | 967 emit_stack_save (enum save_level save_level, rtx *psave) |
950 { | 968 { |
951 rtx sa = *psave; | 969 rtx sa = *psave; |
952 /* The default is that we use a move insn and save in a Pmode object. */ | 970 /* The default is that we use a move insn and save in a Pmode object. */ |
953 rtx (*fcn) (rtx, rtx) = gen_move_insn; | 971 rtx (*fcn) (rtx, rtx) = gen_move_insn; |
954 enum machine_mode mode = STACK_SAVEAREA_MODE (save_level); | 972 enum machine_mode mode = STACK_SAVEAREA_MODE (save_level); |
990 else | 1008 else |
991 *psave = sa = gen_reg_rtx (mode); | 1009 *psave = sa = gen_reg_rtx (mode); |
992 } | 1010 } |
993 } | 1011 } |
994 | 1012 |
995 if (after) | 1013 do_pending_stack_adjust (); |
996 { | 1014 if (sa != 0) |
997 rtx seq; | 1015 sa = validize_mem (sa); |
998 | 1016 emit_insn (fcn (sa, stack_pointer_rtx)); |
999 start_sequence (); | |
1000 do_pending_stack_adjust (); | |
1001 /* We must validize inside the sequence, to ensure that any instructions | |
1002 created by the validize call also get moved to the right place. */ | |
1003 if (sa != 0) | |
1004 sa = validize_mem (sa); | |
1005 emit_insn (fcn (sa, stack_pointer_rtx)); | |
1006 seq = get_insns (); | |
1007 end_sequence (); | |
1008 emit_insn_after (seq, after); | |
1009 } | |
1010 else | |
1011 { | |
1012 do_pending_stack_adjust (); | |
1013 if (sa != 0) | |
1014 sa = validize_mem (sa); | |
1015 emit_insn (fcn (sa, stack_pointer_rtx)); | |
1016 } | |
1017 } | 1017 } |
1018 | 1018 |
1019 /* Restore the stack pointer for the purpose in SAVE_LEVEL. SA is the save | 1019 /* Restore the stack pointer for the purpose in SAVE_LEVEL. SA is the save |
1020 area made by emit_stack_save. If it is zero, we have nothing to do. | 1020 area made by emit_stack_save. If it is zero, we have nothing to do. */ |
1021 | |
1022 Put any emitted insns after insn AFTER, if nonzero, otherwise at | |
1023 current position. */ | |
1024 | 1021 |
1025 void | 1022 void |
1026 emit_stack_restore (enum save_level save_level, rtx sa, rtx after) | 1023 emit_stack_restore (enum save_level save_level, rtx sa) |
1027 { | 1024 { |
1028 /* The default is that we use a move insn. */ | 1025 /* The default is that we use a move insn. */ |
1029 rtx (*fcn) (rtx, rtx) = gen_move_insn; | 1026 rtx (*fcn) (rtx, rtx) = gen_move_insn; |
1030 | 1027 |
1031 /* See if this machine has anything special to do for this kind of save. */ | 1028 /* See if this machine has anything special to do for this kind of save. */ |
1063 emit_clobber (gen_rtx_MEM (BLKmode, stack_pointer_rtx)); | 1060 emit_clobber (gen_rtx_MEM (BLKmode, stack_pointer_rtx)); |
1064 } | 1061 } |
1065 | 1062 |
1066 discard_pending_stack_adjust (); | 1063 discard_pending_stack_adjust (); |
1067 | 1064 |
1068 if (after) | 1065 emit_insn (fcn (stack_pointer_rtx, sa)); |
1069 { | |
1070 rtx seq; | |
1071 | |
1072 start_sequence (); | |
1073 emit_insn (fcn (stack_pointer_rtx, sa)); | |
1074 seq = get_insns (); | |
1075 end_sequence (); | |
1076 emit_insn_after (seq, after); | |
1077 } | |
1078 else | |
1079 emit_insn (fcn (stack_pointer_rtx, sa)); | |
1080 } | 1066 } |
1081 | 1067 |
1082 /* Invoke emit_stack_save on the nonlocal_goto_save_area for the current | 1068 /* Invoke emit_stack_save on the nonlocal_goto_save_area for the current |
1083 function. This function should be called whenever we allocate or | 1069 function. This function should be called whenever we allocate or |
1084 deallocate dynamic stack space. */ | 1070 deallocate dynamic stack space. */ |
1095 of the stack save area slots. */ | 1081 of the stack save area slots. */ |
1096 t_save = build4 (ARRAY_REF, ptr_type_node, cfun->nonlocal_goto_save_area, | 1082 t_save = build4 (ARRAY_REF, ptr_type_node, cfun->nonlocal_goto_save_area, |
1097 integer_one_node, NULL_TREE, NULL_TREE); | 1083 integer_one_node, NULL_TREE, NULL_TREE); |
1098 r_save = expand_expr (t_save, NULL_RTX, VOIDmode, EXPAND_WRITE); | 1084 r_save = expand_expr (t_save, NULL_RTX, VOIDmode, EXPAND_WRITE); |
1099 | 1085 |
1100 emit_stack_save (SAVE_NONLOCAL, &r_save, NULL_RTX); | 1086 emit_stack_save (SAVE_NONLOCAL, &r_save); |
1101 } | 1087 } |
1102 | 1088 |
1103 /* Return an rtx representing the address of an area of memory dynamically | 1089 /* Return an rtx representing the address of an area of memory dynamically |
1104 pushed on the stack. This region of memory is always aligned to | 1090 pushed on the stack. |
1105 a multiple of BIGGEST_ALIGNMENT. | |
1106 | 1091 |
1107 Any required stack pointer alignment is preserved. | 1092 Any required stack pointer alignment is preserved. |
1108 | 1093 |
1109 SIZE is an rtx representing the size of the area. | 1094 SIZE is an rtx representing the size of the area. |
1110 TARGET is a place in which the address can be placed. | 1095 |
1111 | 1096 SIZE_ALIGN is the alignment (in bits) that we know SIZE has. This |
1112 KNOWN_ALIGN is the alignment (in bits) that we know SIZE has. */ | 1097 parameter may be zero. If so, a proper value will be extracted |
1098 from SIZE if it is constant, otherwise BITS_PER_UNIT will be assumed. | |
1099 | |
1100 REQUIRED_ALIGN is the alignment (in bits) required for the region | |
1101 of memory. | |
1102 | |
1103 If CANNOT_ACCUMULATE is set to TRUE, the caller guarantees that the | |
1104 stack space allocated by the generated code cannot be added with itself | |
1105 in the course of the execution of the function. It is always safe to | |
1106 pass FALSE here and the following criterion is sufficient in order to | |
1107 pass TRUE: every path in the CFG that starts at the allocation point and | |
1108 loops to it executes the associated deallocation code. */ | |
1113 | 1109 |
1114 rtx | 1110 rtx |
1115 allocate_dynamic_stack_space (rtx size, rtx target, int known_align) | 1111 allocate_dynamic_stack_space (rtx size, unsigned size_align, |
1116 { | 1112 unsigned required_align, bool cannot_accumulate) |
1113 { | |
1114 HOST_WIDE_INT stack_usage_size = -1; | |
1115 rtx final_label, final_target, target; | |
1116 unsigned extra_align = 0; | |
1117 bool must_align; | |
1118 | |
1117 /* If we're asking for zero bytes, it doesn't matter what we point | 1119 /* If we're asking for zero bytes, it doesn't matter what we point |
1118 to since we can't dereference it. But return a reasonable | 1120 to since we can't dereference it. But return a reasonable |
1119 address anyway. */ | 1121 address anyway. */ |
1120 if (size == const0_rtx) | 1122 if (size == const0_rtx) |
1121 return virtual_stack_dynamic_rtx; | 1123 return virtual_stack_dynamic_rtx; |
1122 | 1124 |
1123 /* Otherwise, show we're calling alloca or equivalent. */ | 1125 /* Otherwise, show we're calling alloca or equivalent. */ |
1124 cfun->calls_alloca = 1; | 1126 cfun->calls_alloca = 1; |
1125 | 1127 |
1128 /* If stack usage info is requested, look into the size we are passed. | |
1129 We need to do so this early to avoid the obfuscation that may be | |
1130 introduced later by the various alignment operations. */ | |
1131 if (flag_stack_usage) | |
1132 { | |
1133 if (CONST_INT_P (size)) | |
1134 stack_usage_size = INTVAL (size); | |
1135 else if (REG_P (size)) | |
1136 { | |
1137 /* Look into the last emitted insn and see if we can deduce | |
1138 something for the register. */ | |
1139 rtx insn, set, note; | |
1140 insn = get_last_insn (); | |
1141 if ((set = single_set (insn)) && rtx_equal_p (SET_DEST (set), size)) | |
1142 { | |
1143 if (CONST_INT_P (SET_SRC (set))) | |
1144 stack_usage_size = INTVAL (SET_SRC (set)); | |
1145 else if ((note = find_reg_equal_equiv_note (insn)) | |
1146 && CONST_INT_P (XEXP (note, 0))) | |
1147 stack_usage_size = INTVAL (XEXP (note, 0)); | |
1148 } | |
1149 } | |
1150 | |
1151 /* If the size is not constant, we can't say anything. */ | |
1152 if (stack_usage_size == -1) | |
1153 { | |
1154 current_function_has_unbounded_dynamic_stack_size = 1; | |
1155 stack_usage_size = 0; | |
1156 } | |
1157 } | |
1158 | |
1126 /* Ensure the size is in the proper mode. */ | 1159 /* Ensure the size is in the proper mode. */ |
1127 if (GET_MODE (size) != VOIDmode && GET_MODE (size) != Pmode) | 1160 if (GET_MODE (size) != VOIDmode && GET_MODE (size) != Pmode) |
1128 size = convert_to_mode (Pmode, size, 1); | 1161 size = convert_to_mode (Pmode, size, 1); |
1129 | 1162 |
1163 /* Adjust SIZE_ALIGN, if needed. */ | |
1164 if (CONST_INT_P (size)) | |
1165 { | |
1166 unsigned HOST_WIDE_INT lsb; | |
1167 | |
1168 lsb = INTVAL (size); | |
1169 lsb &= -lsb; | |
1170 | |
1171 /* Watch out for overflow truncating to "unsigned". */ | |
1172 if (lsb > UINT_MAX / BITS_PER_UNIT) | |
1173 size_align = 1u << (HOST_BITS_PER_INT - 1); | |
1174 else | |
1175 size_align = (unsigned)lsb * BITS_PER_UNIT; | |
1176 } | |
1177 else if (size_align < BITS_PER_UNIT) | |
1178 size_align = BITS_PER_UNIT; | |
1179 | |
1130 /* We can't attempt to minimize alignment necessary, because we don't | 1180 /* We can't attempt to minimize alignment necessary, because we don't |
1131 know the final value of preferred_stack_boundary yet while executing | 1181 know the final value of preferred_stack_boundary yet while executing |
1132 this code. */ | 1182 this code. */ |
1133 crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY; | 1183 if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY) |
1184 crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY; | |
1134 | 1185 |
1135 /* We will need to ensure that the address we return is aligned to | 1186 /* We will need to ensure that the address we return is aligned to |
1136 BIGGEST_ALIGNMENT. If STACK_DYNAMIC_OFFSET is defined, we don't | 1187 REQUIRED_ALIGN. If STACK_DYNAMIC_OFFSET is defined, we don't |
1137 always know its final value at this point in the compilation (it | 1188 always know its final value at this point in the compilation (it |
1138 might depend on the size of the outgoing parameter lists, for | 1189 might depend on the size of the outgoing parameter lists, for |
1139 example), so we must align the value to be returned in that case. | 1190 example), so we must align the value to be returned in that case. |
1140 (Note that STACK_DYNAMIC_OFFSET will have a default nonzero value if | 1191 (Note that STACK_DYNAMIC_OFFSET will have a default nonzero value if |
1141 STACK_POINTER_OFFSET or ACCUMULATE_OUTGOING_ARGS are defined). | 1192 STACK_POINTER_OFFSET or ACCUMULATE_OUTGOING_ARGS are defined). |
1142 We must also do an alignment operation on the returned value if | 1193 We must also do an alignment operation on the returned value if |
1143 the stack pointer alignment is less strict that BIGGEST_ALIGNMENT. | 1194 the stack pointer alignment is less strict than REQUIRED_ALIGN. |
1144 | 1195 |
1145 If we have to align, we must leave space in SIZE for the hole | 1196 If we have to align, we must leave space in SIZE for the hole |
1146 that might result from the alignment operation. */ | 1197 that might result from the alignment operation. */ |
1147 | 1198 |
1199 must_align = (crtl->preferred_stack_boundary < required_align); | |
1200 if (must_align) | |
1201 { | |
1202 if (required_align > PREFERRED_STACK_BOUNDARY) | |
1203 extra_align = PREFERRED_STACK_BOUNDARY; | |
1204 else if (required_align > STACK_BOUNDARY) | |
1205 extra_align = STACK_BOUNDARY; | |
1206 else | |
1207 extra_align = BITS_PER_UNIT; | |
1208 } | |
1209 | |
1210 /* ??? STACK_POINTER_OFFSET is always defined now. */ | |
1148 #if defined (STACK_DYNAMIC_OFFSET) || defined (STACK_POINTER_OFFSET) | 1211 #if defined (STACK_DYNAMIC_OFFSET) || defined (STACK_POINTER_OFFSET) |
1149 #define MUST_ALIGN 1 | 1212 must_align = true; |
1150 #else | 1213 extra_align = BITS_PER_UNIT; |
1151 #define MUST_ALIGN (PREFERRED_STACK_BOUNDARY < BIGGEST_ALIGNMENT) | |
1152 #endif | 1214 #endif |
1153 | 1215 |
1154 if (MUST_ALIGN) | 1216 if (must_align) |
1155 size | 1217 { |
1156 = force_operand (plus_constant (size, | 1218 unsigned extra = (required_align - extra_align) / BITS_PER_UNIT; |
1157 BIGGEST_ALIGNMENT / BITS_PER_UNIT - 1), | 1219 |
1158 NULL_RTX); | 1220 size = plus_constant (size, extra); |
1221 size = force_operand (size, NULL_RTX); | |
1222 | |
1223 if (flag_stack_usage) | |
1224 stack_usage_size += extra; | |
1225 | |
1226 if (extra && size_align > extra_align) | |
1227 size_align = extra_align; | |
1228 } | |
1159 | 1229 |
1160 #ifdef SETJMP_VIA_SAVE_AREA | 1230 #ifdef SETJMP_VIA_SAVE_AREA |
1161 /* If setjmp restores regs from a save area in the stack frame, | 1231 /* If setjmp restores regs from a save area in the stack frame, |
1162 avoid clobbering the reg save area. Note that the offset of | 1232 avoid clobbering the reg save area. Note that the offset of |
1163 virtual_incoming_args_rtx includes the preallocated stack args space. | 1233 virtual_incoming_args_rtx includes the preallocated stack args space. |
1167 What used to happen is that, since we did not know for sure | 1237 What used to happen is that, since we did not know for sure |
1168 whether setjmp() was invoked until after RTL generation, we | 1238 whether setjmp() was invoked until after RTL generation, we |
1169 would use reg notes to store the "optimized" size and fix things | 1239 would use reg notes to store the "optimized" size and fix things |
1170 up later. These days we know this information before we ever | 1240 up later. These days we know this information before we ever |
1171 start building RTL so the reg notes are unnecessary. */ | 1241 start building RTL so the reg notes are unnecessary. */ |
1172 if (!cfun->calls_setjmp) | 1242 if (cfun->calls_setjmp) |
1173 { | |
1174 int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; | |
1175 | |
1176 /* ??? Code below assumes that the save area needs maximal | |
1177 alignment. This constraint may be too strong. */ | |
1178 gcc_assert (PREFERRED_STACK_BOUNDARY == BIGGEST_ALIGNMENT); | |
1179 | |
1180 if (CONST_INT_P (size)) | |
1181 { | |
1182 HOST_WIDE_INT new_size = INTVAL (size) / align * align; | |
1183 | |
1184 if (INTVAL (size) != new_size) | |
1185 size = GEN_INT (new_size); | |
1186 } | |
1187 else | |
1188 { | |
1189 /* Since we know overflow is not possible, we avoid using | |
1190 CEIL_DIV_EXPR and use TRUNC_DIV_EXPR instead. */ | |
1191 size = expand_divmod (0, TRUNC_DIV_EXPR, Pmode, size, | |
1192 GEN_INT (align), NULL_RTX, 1); | |
1193 size = expand_mult (Pmode, size, | |
1194 GEN_INT (align), NULL_RTX, 1); | |
1195 } | |
1196 } | |
1197 else | |
1198 { | 1243 { |
1199 rtx dynamic_offset | 1244 rtx dynamic_offset |
1200 = expand_binop (Pmode, sub_optab, virtual_stack_dynamic_rtx, | 1245 = expand_binop (Pmode, sub_optab, virtual_stack_dynamic_rtx, |
1201 stack_pointer_rtx, NULL_RTX, 1, OPTAB_LIB_WIDEN); | 1246 stack_pointer_rtx, NULL_RTX, 1, OPTAB_LIB_WIDEN); |
1202 | 1247 |
1203 size = expand_binop (Pmode, add_optab, size, dynamic_offset, | 1248 size = expand_binop (Pmode, add_optab, size, dynamic_offset, |
1204 NULL_RTX, 1, OPTAB_LIB_WIDEN); | 1249 NULL_RTX, 1, OPTAB_LIB_WIDEN); |
1250 | |
1251 /* The above dynamic offset cannot be computed statically at this | |
1252 point, but it will be possible to do so after RTL expansion is | |
1253 done. Record how many times we will need to add it. */ | |
1254 if (flag_stack_usage) | |
1255 current_function_dynamic_alloc_count++; | |
1256 | |
1257 /* ??? Can we infer a minimum of STACK_BOUNDARY here? */ | |
1258 size_align = BITS_PER_UNIT; | |
1205 } | 1259 } |
1206 #endif /* SETJMP_VIA_SAVE_AREA */ | 1260 #endif /* SETJMP_VIA_SAVE_AREA */ |
1207 | 1261 |
1208 /* Round the size to a multiple of the required stack alignment. | 1262 /* Round the size to a multiple of the required stack alignment. |
1209 Since the stack if presumed to be rounded before this allocation, | 1263 Since the stack if presumed to be rounded before this allocation, |
1216 some machines do not allow this. Even on those that do, some | 1270 some machines do not allow this. Even on those that do, some |
1217 signal handlers malfunction if a signal should occur between those | 1271 signal handlers malfunction if a signal should occur between those |
1218 insns. Since this is an extremely rare event, we have no reliable | 1272 insns. Since this is an extremely rare event, we have no reliable |
1219 way of knowing which systems have this problem. So we avoid even | 1273 way of knowing which systems have this problem. So we avoid even |
1220 momentarily mis-aligning the stack. */ | 1274 momentarily mis-aligning the stack. */ |
1221 | 1275 if (size_align % MAX_SUPPORTED_STACK_ALIGNMENT != 0) |
1222 /* If we added a variable amount to SIZE, | 1276 { |
1223 we can no longer assume it is aligned. */ | 1277 size = round_push (size); |
1224 #if !defined (SETJMP_VIA_SAVE_AREA) | 1278 |
1225 if (MUST_ALIGN || known_align % PREFERRED_STACK_BOUNDARY != 0) | 1279 if (flag_stack_usage) |
1280 { | |
1281 int align = crtl->preferred_stack_boundary / BITS_PER_UNIT; | |
1282 stack_usage_size = (stack_usage_size + align - 1) / align * align; | |
1283 } | |
1284 } | |
1285 | |
1286 target = gen_reg_rtx (Pmode); | |
1287 | |
1288 /* The size is supposed to be fully adjusted at this point so record it | |
1289 if stack usage info is requested. */ | |
1290 if (flag_stack_usage) | |
1291 { | |
1292 current_function_dynamic_stack_size += stack_usage_size; | |
1293 | |
1294 /* ??? This is gross but the only safe stance in the absence | |
1295 of stack usage oriented flow analysis. */ | |
1296 if (!cannot_accumulate) | |
1297 current_function_has_unbounded_dynamic_stack_size = 1; | |
1298 } | |
1299 | |
1300 final_label = NULL_RTX; | |
1301 final_target = NULL_RTX; | |
1302 | |
1303 /* If we are splitting the stack, we need to ask the backend whether | |
1304 there is enough room on the current stack. If there isn't, or if | |
1305 the backend doesn't know how to tell is, then we need to call a | |
1306 function to allocate memory in some other way. This memory will | |
1307 be released when we release the current stack segment. The | |
1308 effect is that stack allocation becomes less efficient, but at | |
1309 least it doesn't cause a stack overflow. */ | |
1310 if (flag_split_stack) | |
1311 { | |
1312 rtx available_label, ask, space, func; | |
1313 | |
1314 available_label = NULL_RTX; | |
1315 | |
1316 #ifdef HAVE_split_stack_space_check | |
1317 if (HAVE_split_stack_space_check) | |
1318 { | |
1319 available_label = gen_label_rtx (); | |
1320 | |
1321 /* This instruction will branch to AVAILABLE_LABEL if there | |
1322 are SIZE bytes available on the stack. */ | |
1323 emit_insn (gen_split_stack_space_check (size, available_label)); | |
1324 } | |
1226 #endif | 1325 #endif |
1227 size = round_push (size); | 1326 |
1327 /* The __morestack_allocate_stack_space function will allocate | |
1328 memory using malloc. If the alignment of the memory returned | |
1329 by malloc does not meet REQUIRED_ALIGN, we increase SIZE to | |
1330 make sure we allocate enough space. */ | |
1331 if (MALLOC_ABI_ALIGNMENT >= required_align) | |
1332 ask = size; | |
1333 else | |
1334 { | |
1335 ask = expand_binop (Pmode, add_optab, size, | |
1336 GEN_INT (required_align / BITS_PER_UNIT - 1), | |
1337 NULL_RTX, 1, OPTAB_LIB_WIDEN); | |
1338 must_align = true; | |
1339 } | |
1340 | |
1341 func = init_one_libfunc ("__morestack_allocate_stack_space"); | |
1342 | |
1343 space = emit_library_call_value (func, target, LCT_NORMAL, Pmode, | |
1344 1, ask, Pmode); | |
1345 | |
1346 if (available_label == NULL_RTX) | |
1347 return space; | |
1348 | |
1349 final_target = gen_reg_rtx (Pmode); | |
1350 | |
1351 emit_move_insn (final_target, space); | |
1352 | |
1353 final_label = gen_label_rtx (); | |
1354 emit_jump (final_label); | |
1355 | |
1356 emit_label (available_label); | |
1357 } | |
1228 | 1358 |
1229 do_pending_stack_adjust (); | 1359 do_pending_stack_adjust (); |
1230 | 1360 |
1231 /* We ought to be called always on the toplevel and stack ought to be aligned | 1361 /* We ought to be called always on the toplevel and stack ought to be aligned |
1232 properly. */ | 1362 properly. */ |
1241 probe_stack_range (STACK_OLD_CHECK_PROTECT + STACK_CHECK_MAX_FRAME_SIZE, | 1371 probe_stack_range (STACK_OLD_CHECK_PROTECT + STACK_CHECK_MAX_FRAME_SIZE, |
1242 size); | 1372 size); |
1243 else if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK) | 1373 else if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK) |
1244 probe_stack_range (STACK_CHECK_PROTECT, size); | 1374 probe_stack_range (STACK_CHECK_PROTECT, size); |
1245 | 1375 |
1246 /* Don't use a TARGET that isn't a pseudo or is the wrong mode. */ | |
1247 if (target == 0 || !REG_P (target) | |
1248 || REGNO (target) < FIRST_PSEUDO_REGISTER | |
1249 || GET_MODE (target) != Pmode) | |
1250 target = gen_reg_rtx (Pmode); | |
1251 | |
1252 mark_reg_pointer (target, known_align); | |
1253 | |
1254 /* Perform the required allocation from the stack. Some systems do | 1376 /* Perform the required allocation from the stack. Some systems do |
1255 this differently than simply incrementing/decrementing from the | 1377 this differently than simply incrementing/decrementing from the |
1256 stack pointer, such as acquiring the space by calling malloc(). */ | 1378 stack pointer, such as acquiring the space by calling malloc(). */ |
1257 #ifdef HAVE_allocate_stack | 1379 #ifdef HAVE_allocate_stack |
1258 if (HAVE_allocate_stack) | 1380 if (HAVE_allocate_stack) |
1274 emit_insn (gen_allocate_stack (target, size)); | 1396 emit_insn (gen_allocate_stack (target, size)); |
1275 } | 1397 } |
1276 else | 1398 else |
1277 #endif | 1399 #endif |
1278 { | 1400 { |
1401 int saved_stack_pointer_delta; | |
1402 | |
1279 #ifndef STACK_GROWS_DOWNWARD | 1403 #ifndef STACK_GROWS_DOWNWARD |
1280 emit_move_insn (target, virtual_stack_dynamic_rtx); | 1404 emit_move_insn (target, virtual_stack_dynamic_rtx); |
1281 #endif | 1405 #endif |
1282 | 1406 |
1283 /* Check stack bounds if necessary. */ | 1407 /* Check stack bounds if necessary. */ |
1304 error ("stack limits not supported on this target"); | 1428 error ("stack limits not supported on this target"); |
1305 emit_barrier (); | 1429 emit_barrier (); |
1306 emit_label (space_available); | 1430 emit_label (space_available); |
1307 } | 1431 } |
1308 | 1432 |
1433 saved_stack_pointer_delta = stack_pointer_delta; | |
1309 if (flag_stack_check && STACK_CHECK_MOVING_SP) | 1434 if (flag_stack_check && STACK_CHECK_MOVING_SP) |
1310 anti_adjust_stack_and_probe (size, false); | 1435 anti_adjust_stack_and_probe (size, false); |
1311 else | 1436 else |
1312 anti_adjust_stack (size); | 1437 anti_adjust_stack (size); |
1438 /* Even if size is constant, don't modify stack_pointer_delta. | |
1439 The constant size alloca should preserve | |
1440 crtl->preferred_stack_boundary alignment. */ | |
1441 stack_pointer_delta = saved_stack_pointer_delta; | |
1313 | 1442 |
1314 #ifdef STACK_GROWS_DOWNWARD | 1443 #ifdef STACK_GROWS_DOWNWARD |
1315 emit_move_insn (target, virtual_stack_dynamic_rtx); | 1444 emit_move_insn (target, virtual_stack_dynamic_rtx); |
1316 #endif | 1445 #endif |
1317 } | 1446 } |
1318 | 1447 |
1319 if (MUST_ALIGN) | 1448 /* Finish up the split stack handling. */ |
1449 if (final_label != NULL_RTX) | |
1450 { | |
1451 gcc_assert (flag_split_stack); | |
1452 emit_move_insn (final_target, target); | |
1453 emit_label (final_label); | |
1454 target = final_target; | |
1455 } | |
1456 | |
1457 if (must_align) | |
1320 { | 1458 { |
1321 /* CEIL_DIV_EXPR needs to worry about the addition overflowing, | 1459 /* CEIL_DIV_EXPR needs to worry about the addition overflowing, |
1322 but we know it can't. So add ourselves and then do | 1460 but we know it can't. So add ourselves and then do |
1323 TRUNC_DIV_EXPR. */ | 1461 TRUNC_DIV_EXPR. */ |
1324 target = expand_binop (Pmode, add_optab, target, | 1462 target = expand_binop (Pmode, add_optab, target, |
1325 GEN_INT (BIGGEST_ALIGNMENT / BITS_PER_UNIT - 1), | 1463 GEN_INT (required_align / BITS_PER_UNIT - 1), |
1326 NULL_RTX, 1, OPTAB_LIB_WIDEN); | 1464 NULL_RTX, 1, OPTAB_LIB_WIDEN); |
1327 target = expand_divmod (0, TRUNC_DIV_EXPR, Pmode, target, | 1465 target = expand_divmod (0, TRUNC_DIV_EXPR, Pmode, target, |
1328 GEN_INT (BIGGEST_ALIGNMENT / BITS_PER_UNIT), | 1466 GEN_INT (required_align / BITS_PER_UNIT), |
1329 NULL_RTX, 1); | 1467 NULL_RTX, 1); |
1330 target = expand_mult (Pmode, target, | 1468 target = expand_mult (Pmode, target, |
1331 GEN_INT (BIGGEST_ALIGNMENT / BITS_PER_UNIT), | 1469 GEN_INT (required_align / BITS_PER_UNIT), |
1332 NULL_RTX, 1); | 1470 NULL_RTX, 1); |
1333 } | 1471 } |
1472 | |
1473 /* Now that we've committed to a return value, mark its alignment. */ | |
1474 mark_reg_pointer (target, required_align); | |
1334 | 1475 |
1335 /* Record the new stack level for nonlocal gotos. */ | 1476 /* Record the new stack level for nonlocal gotos. */ |
1336 if (cfun->nonlocal_goto_save_area != 0) | 1477 if (cfun->nonlocal_goto_save_area != 0) |
1337 update_nonlocal_goto_save_area (); | 1478 update_nonlocal_goto_save_area (); |
1338 | 1479 |
1344 calling that routine. */ | 1485 calling that routine. */ |
1345 | 1486 |
1346 static GTY(()) rtx stack_check_libfunc; | 1487 static GTY(()) rtx stack_check_libfunc; |
1347 | 1488 |
1348 void | 1489 void |
1349 set_stack_check_libfunc (rtx libfunc) | 1490 set_stack_check_libfunc (const char *libfunc_name) |
1350 { | 1491 { |
1351 stack_check_libfunc = libfunc; | 1492 gcc_assert (stack_check_libfunc == NULL_RTX); |
1493 stack_check_libfunc = gen_rtx_SYMBOL_REF (Pmode, libfunc_name); | |
1352 } | 1494 } |
1353 | 1495 |
1354 /* Emit one stack probe at ADDRESS, an address within the stack. */ | 1496 /* Emit one stack probe at ADDRESS, an address within the stack. */ |
1355 | 1497 |
1356 static void | 1498 void |
1357 emit_stack_probe (rtx address) | 1499 emit_stack_probe (rtx address) |
1358 { | 1500 { |
1359 rtx memref = gen_rtx_MEM (word_mode, address); | 1501 rtx memref = gen_rtx_MEM (word_mode, address); |
1360 | 1502 |
1361 MEM_VOLATILE_P (memref) = 1; | 1503 MEM_VOLATILE_P (memref) = 1; |
1517 temp = simplify_gen_binary (MINUS, Pmode, size, rounded_size); | 1659 temp = simplify_gen_binary (MINUS, Pmode, size, rounded_size); |
1518 if (temp != const0_rtx) | 1660 if (temp != const0_rtx) |
1519 { | 1661 { |
1520 rtx addr; | 1662 rtx addr; |
1521 | 1663 |
1522 if (GET_CODE (temp) == CONST_INT) | 1664 if (CONST_INT_P (temp)) |
1523 { | 1665 { |
1524 /* Use [base + disp} addressing mode if supported. */ | 1666 /* Use [base + disp} addressing mode if supported. */ |
1525 HOST_WIDE_INT offset = INTVAL (temp); | 1667 HOST_WIDE_INT offset = INTVAL (temp); |
1526 addr = memory_address (Pmode, | 1668 addr = memory_address (Pmode, |
1527 plus_constant (last_addr, | 1669 plus_constant (last_addr, |
1558 if (GET_MODE (size) != VOIDmode && GET_MODE (size) != Pmode) | 1700 if (GET_MODE (size) != VOIDmode && GET_MODE (size) != Pmode) |
1559 size = convert_to_mode (Pmode, size, 1); | 1701 size = convert_to_mode (Pmode, size, 1); |
1560 | 1702 |
1561 /* If we have a constant small number of probes to generate, that's the | 1703 /* If we have a constant small number of probes to generate, that's the |
1562 easy case. */ | 1704 easy case. */ |
1563 if (GET_CODE (size) == CONST_INT && INTVAL (size) < 7 * PROBE_INTERVAL) | 1705 if (CONST_INT_P (size) && INTVAL (size) < 7 * PROBE_INTERVAL) |
1564 { | 1706 { |
1565 HOST_WIDE_INT isize = INTVAL (size), i; | 1707 HOST_WIDE_INT isize = INTVAL (size), i; |
1566 bool first_probe = true; | 1708 bool first_probe = true; |
1567 | 1709 |
1568 /* Adjust SP and probe to PROBE_INTERVAL + N * PROBE_INTERVAL for | 1710 /* Adjust SP and probe at PROBE_INTERVAL + N * PROBE_INTERVAL for |
1569 values of N from 1 until it exceeds SIZE. If only one probe is | 1711 values of N from 1 until it exceeds SIZE. If only one probe is |
1570 needed, this will not generate any code. Then adjust and probe | 1712 needed, this will not generate any code. Then adjust and probe |
1571 to PROBE_INTERVAL + SIZE. */ | 1713 to PROBE_INTERVAL + SIZE. */ |
1572 for (i = PROBE_INTERVAL; i < isize; i += PROBE_INTERVAL) | 1714 for (i = PROBE_INTERVAL; i < isize; i += PROBE_INTERVAL) |
1573 { | 1715 { |
1619 rounded_size_op), NULL_RTX); | 1761 rounded_size_op), NULL_RTX); |
1620 | 1762 |
1621 | 1763 |
1622 /* Step 3: the loop | 1764 /* Step 3: the loop |
1623 | 1765 |
1624 while (SP != LAST_ADDR) | 1766 while (SP != LAST_ADDR) |
1625 { | 1767 { |
1626 SP = SP + PROBE_INTERVAL | 1768 SP = SP + PROBE_INTERVAL |
1627 probe at SP | 1769 probe at SP |
1628 } | 1770 } |
1629 | 1771 |
1630 adjusts SP and probes to PROBE_INTERVAL + N * PROBE_INTERVAL for | 1772 adjusts SP and probes at PROBE_INTERVAL + N * PROBE_INTERVAL for |
1631 values of N from 1 until it is equal to ROUNDED_SIZE. */ | 1773 values of N from 1 until it is equal to ROUNDED_SIZE. */ |
1632 | 1774 |
1633 emit_label (loop_lab); | 1775 emit_label (loop_lab); |
1634 | 1776 |
1635 /* Jump to END_LAB if SP == LAST_ADDR. */ | 1777 /* Jump to END_LAB if SP == LAST_ADDR. */ |
1643 emit_jump (loop_lab); | 1785 emit_jump (loop_lab); |
1644 | 1786 |
1645 emit_label (end_lab); | 1787 emit_label (end_lab); |
1646 | 1788 |
1647 | 1789 |
1648 /* Step 4: adjust SP and probe to PROBE_INTERVAL + SIZE if we cannot | 1790 /* Step 4: adjust SP and probe at PROBE_INTERVAL + SIZE if we cannot |
1649 assert at compile-time that SIZE is equal to ROUNDED_SIZE. */ | 1791 assert at compile-time that SIZE is equal to ROUNDED_SIZE. */ |
1650 | 1792 |
1651 /* TEMP = SIZE - ROUNDED_SIZE. */ | 1793 /* TEMP = SIZE - ROUNDED_SIZE. */ |
1652 temp = simplify_gen_binary (MINUS, Pmode, size, rounded_size); | 1794 temp = simplify_gen_binary (MINUS, Pmode, size, rounded_size); |
1653 if (temp != const0_rtx) | 1795 if (temp != const0_rtx) |