1 diff -Naurp gcc/config/avr/avr.c gcc/config/avr/avr.c
2 --- gcc/config/avr/avr.c 2012-06-22 15:29:05.000000000 +0530
3 +++ gcc/config/avr/avr.c 2012-06-28 12:50:23.000000000 +0530
4 @@ -111,6 +111,9 @@ static void avr_help (void);
5 /* Allocate registers from r25 to r8 for parameters for function calls. */
6 #define FIRST_CUM_REG 26
8 +/* Last call saved register */
9 +#define LAST_CALLEE_SAVED_REG (AVR_TINY ? 21 : 17)
11 /* Temporary register RTX (gen_rtx_REG (QImode, TMP_REGNO)) */
12 static GTY(()) rtx tmp_reg_rtx;
14 @@ -611,7 +614,7 @@ sequent_regs_live (void)
18 - for (reg = 0; reg < 18; ++reg)
19 + for (reg = 0; reg <= LAST_CALLEE_SAVED_REG; ++reg)
23 @@ -838,11 +841,11 @@ expand_prologue (void)
25 /* Note that live_seq always contains r28+r29, but the other
26 registers to be saved are all below 18. */
27 - first_reg = 18 - (live_seq - 2);
28 + first_reg = (LAST_CALLEE_SAVED_REG + 1) - (live_seq - 2);
30 for (reg = 29, offset = -live_seq + 1;
32 - reg = (reg == 28 ? 17 : reg - 1), ++offset)
33 + reg = (reg == 28 ? (LAST_CALLEE_SAVED_REG) : reg - 1), ++offset)
37 @@ -6375,6 +6378,17 @@ order_regs_for_local_alloc (void)
41 + static const int tiny_order_0[] = {
50 + 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
52 static const int order_1[] = {
55 @@ -6387,6 +6401,17 @@ order_regs_for_local_alloc (void)
59 + static const int tiny_order_1[] = {
68 + 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
70 static const int order_2[] = {
73 @@ -6400,10 +6425,15 @@ order_regs_for_local_alloc (void)
78 - const int *order = (TARGET_ORDER_1 ? order_1 :
79 - TARGET_ORDER_2 ? order_2 :
83 + Select specific register allocation order. Tiny Core (attiny4/5/9/10/20/40)
84 + devices has only 16 registers, so different allocation order should be used
86 + const int *order = (TARGET_ORDER_1 ? (AVR_TINY ? tiny_order_1 : order_1) :
87 + TARGET_ORDER_2 ? (AVR_TINY ? tiny_order_1 : order_2) :
88 + (AVR_TINY ? tiny_order_0 : order_0));
90 for (i=0; i < ARRAY_SIZE (order_0); ++i)
91 reg_alloc_order[i] = order[i];
93 @@ -7395,15 +7425,45 @@ avr_output_addr_vec_elt (FILE *stream, i
96 avr_conditional_register_usage(void) {
99 - for (i = 0; i <= 17; i++) {
101 - call_used_regs[i] = 1;
103 - CLEAR_HARD_REG_SET(reg_class_contents[(int)ADDW_REGS]);
104 - CLEAR_HARD_REG_SET(reg_class_contents[(int)NO_LD_REGS]);
109 + const int tiny_reg_alloc_order[] = {
118 + 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
121 + /* Set R0-R17 as fixed registers. Reset R0-R17 in call used register list
122 + - R0-R15 are not available in Tiny Core devices
123 + - R16 and R17 are fixed registers
125 + for (i = 0; i <= 17; i++) {
127 + call_used_regs[i] = 1;
130 + /* Set R18 to R21 as call used register
131 + - R18, R19, R20 and R21 are the call used registers in Tiny Core devices
133 + for (i = 18; i <= LAST_CALLEE_SAVED_REG; i++) {
134 + call_used_regs[i] = 0;
137 + /*update register allocation order for Tiny Core devices */
138 + for (i=0; i < ARRAY_SIZE (tiny_reg_alloc_order); i++) {
139 + reg_alloc_order[i] = tiny_reg_alloc_order[i];
142 + CLEAR_HARD_REG_SET(reg_class_contents[(int)ADDW_REGS]);
143 + CLEAR_HARD_REG_SET(reg_class_contents[(int)NO_LD_REGS]);
147 /* Returns true if SCRATCH are safe to be allocated as a scratch
148 @@ -7553,13 +7613,20 @@ avr_asm_out_dtor (rtx symbol, int priori
150 avr_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
152 - if (TYPE_MODE (type) == BLKmode)
154 - HOST_WIDE_INT size = int_size_in_bytes (type);
155 - return (size == -1 || size > 8);
157 + HOST_WIDE_INT size = int_size_in_bytes (type);
158 + HOST_WIDE_INT ret_size_limit = AVR_TINY ? 4 : 8;
160 + /* In avr, there are 8 return registers. But, for Tiny Core
161 + (attiny4/5/9/10/20/40) devices, only 4 registers available.
162 + Return true if size is unknown or greater than the limit */
163 + if ((size == -1) || (size > ret_size_limit))
173 /* Worker function for CASE_VALUES_THRESHOLD. */