1 /* Subroutines for code generation on Motorola 68HC11 and 68HC12.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by Stephane Carrez (stcarrez@nerim.fr)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
24 A first 68HC11 port was made by Otto Lind (otto@coactive.com)
25 on gcc 2.6.3. I have used it as a starting point for this port.
26 However, this new port is a complete re-write. Its internal
27 design is completely different. The generated code is not
28 compatible with the gcc 2.6.3 port.
30 The gcc 2.6.3 port is available at:
32 ftp.unina.it/pub/electronics/motorola/68hc11/gcc/gcc-6811-fsf.tar.gz
39 #include "coretypes.h"
45 #include "hard-reg-set.h"
47 #include "insn-config.h"
48 #include "conditions.h"
50 #include "insn-attr.h"
56 #include "basic-block.h"
61 #include "target-def.h"
63 static void emit_move_after_reload (rtx
, rtx
, rtx
);
64 static rtx
simplify_logical (enum machine_mode
, int, rtx
, rtx
*);
65 static void m68hc11_emit_logical (enum machine_mode
, int, rtx
*);
66 static void m68hc11_reorg (void);
67 static int go_if_legitimate_address_internal (rtx
, enum machine_mode
, int);
68 static rtx
m68hc11_expand_compare (enum rtx_code
, rtx
, rtx
);
69 static int must_parenthesize (rtx
);
70 static int m68hc11_address_cost (rtx
);
71 static int m68hc11_shift_cost (enum machine_mode
, rtx
, int);
72 static int m68hc11_rtx_costs_1 (rtx
, enum rtx_code
, enum rtx_code
);
73 static bool m68hc11_rtx_costs (rtx
, int, int, int *);
74 static tree
m68hc11_handle_fntype_attribute (tree
*, tree
, tree
, int, bool *);
75 const struct attribute_spec m68hc11_attribute_table
[];
77 void create_regs_rtx (void);
79 static void asm_print_register (FILE *, int);
80 static void m68hc11_output_function_epilogue (FILE *, HOST_WIDE_INT
);
81 static void m68hc11_asm_out_constructor (rtx
, int);
82 static void m68hc11_asm_out_destructor (rtx
, int);
83 static void m68hc11_file_start (void);
84 static void m68hc11_encode_section_info (tree
, rtx
, int);
85 static const char *m68hc11_strip_name_encoding (const char* str
);
86 static unsigned int m68hc11_section_type_flags (tree
, const char*, int);
87 static int autoinc_mode (rtx
);
88 static int m68hc11_make_autoinc_notes (rtx
*, void *);
89 static void m68hc11_init_libfuncs (void);
90 static rtx
m68hc11_struct_value_rtx (tree
, int);
91 static bool m68hc11_return_in_memory (tree
, tree
);
93 /* Must be set to 1 to produce debug messages. */
96 extern FILE *asm_out_file
;
101 rtx m68hc11_soft_tmp_reg
;
102 static GTY(()) rtx stack_push_word
;
103 static GTY(()) rtx stack_pop_word
;
104 static GTY(()) rtx z_reg
;
105 static GTY(()) rtx z_reg_qi
;
106 static int regs_inited
= 0;
108 /* Set to 1 by expand_prologue() when the function is an interrupt handler. */
109 int current_function_interrupt
;
111 /* Set to 1 by expand_prologue() when the function is a trap handler. */
112 int current_function_trap
;
114 /* Set to 1 when the current function is placed in 68HC12 banked
115 memory and must return with rtc. */
116 int current_function_far
;
118 /* Min offset that is valid for the indirect addressing mode. */
119 HOST_WIDE_INT m68hc11_min_offset
= 0;
121 /* Max offset that is valid for the indirect addressing mode. */
122 HOST_WIDE_INT m68hc11_max_offset
= 256;
124 /* The class value for base registers. */
125 enum reg_class m68hc11_base_reg_class
= A_REGS
;
127 /* The class value for index registers. This is NO_REGS for 68HC11. */
128 enum reg_class m68hc11_index_reg_class
= NO_REGS
;
130 enum reg_class m68hc11_tmp_regs_class
= NO_REGS
;
132 /* Tables that tell whether a given hard register is valid for
133 a base or an index register. It is filled at init time depending
134 on the target processor. */
135 unsigned char m68hc11_reg_valid_for_base
[FIRST_PSEUDO_REGISTER
];
136 unsigned char m68hc11_reg_valid_for_index
[FIRST_PSEUDO_REGISTER
];
138 /* A correction offset which is applied to the stack pointer.
139 This is 1 for 68HC11 and 0 for 68HC12. */
140 int m68hc11_sp_correction
;
142 int m68hc11_addr_mode
;
143 int m68hc11_mov_addr_mode
;
145 /* Comparison operands saved by the "tstxx" and "cmpxx" expand patterns. */
146 rtx m68hc11_compare_op0
;
147 rtx m68hc11_compare_op1
;
150 const struct processor_costs
*m68hc11_cost
;
152 /* Costs for a 68HC11. */
153 static const struct processor_costs m6811_cost
= {
158 /* non-constant shift */
161 { COSTS_N_INSNS (0), COSTS_N_INSNS (1), COSTS_N_INSNS (2),
162 COSTS_N_INSNS (3), COSTS_N_INSNS (4), COSTS_N_INSNS (3),
163 COSTS_N_INSNS (2), COSTS_N_INSNS (1) },
166 { COSTS_N_INSNS (0), COSTS_N_INSNS (1), COSTS_N_INSNS (4),
167 COSTS_N_INSNS (6), COSTS_N_INSNS (8), COSTS_N_INSNS (6),
168 COSTS_N_INSNS (4), COSTS_N_INSNS (2),
169 COSTS_N_INSNS (2), COSTS_N_INSNS (4),
170 COSTS_N_INSNS (6), COSTS_N_INSNS (8), COSTS_N_INSNS (10),
171 COSTS_N_INSNS (8), COSTS_N_INSNS (6), COSTS_N_INSNS (4)
176 COSTS_N_INSNS (20 * 4),
178 COSTS_N_INSNS (20 * 16),
187 /* Costs for a 68HC12. */
188 static const struct processor_costs m6812_cost
= {
193 /* non-constant shift */
196 { COSTS_N_INSNS (0), COSTS_N_INSNS (1), COSTS_N_INSNS (2),
197 COSTS_N_INSNS (3), COSTS_N_INSNS (4), COSTS_N_INSNS (3),
198 COSTS_N_INSNS (2), COSTS_N_INSNS (1) },
201 { COSTS_N_INSNS (0), COSTS_N_INSNS (1), COSTS_N_INSNS (4),
202 COSTS_N_INSNS (6), COSTS_N_INSNS (8), COSTS_N_INSNS (6),
203 COSTS_N_INSNS (4), COSTS_N_INSNS (2),
204 COSTS_N_INSNS (2), COSTS_N_INSNS (4), COSTS_N_INSNS (6),
205 COSTS_N_INSNS (8), COSTS_N_INSNS (10), COSTS_N_INSNS (8),
206 COSTS_N_INSNS (6), COSTS_N_INSNS (4)
213 COSTS_N_INSNS (3 * 4),
222 /* Initialize the GCC target structure. */
223 #undef TARGET_ATTRIBUTE_TABLE
224 #define TARGET_ATTRIBUTE_TABLE m68hc11_attribute_table
226 #undef TARGET_ASM_ALIGNED_HI_OP
227 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
229 #undef TARGET_ASM_FUNCTION_EPILOGUE
230 #define TARGET_ASM_FUNCTION_EPILOGUE m68hc11_output_function_epilogue
232 #undef TARGET_ASM_FILE_START
233 #define TARGET_ASM_FILE_START m68hc11_file_start
234 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
235 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
237 #undef TARGET_DEFAULT_TARGET_FLAGS
238 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
240 #undef TARGET_ENCODE_SECTION_INFO
241 #define TARGET_ENCODE_SECTION_INFO m68hc11_encode_section_info
243 #undef TARGET_SECTION_TYPE_FLAGS
244 #define TARGET_SECTION_TYPE_FLAGS m68hc11_section_type_flags
246 #undef TARGET_RTX_COSTS
247 #define TARGET_RTX_COSTS m68hc11_rtx_costs
248 #undef TARGET_ADDRESS_COST
249 #define TARGET_ADDRESS_COST m68hc11_address_cost
251 #undef TARGET_MACHINE_DEPENDENT_REORG
252 #define TARGET_MACHINE_DEPENDENT_REORG m68hc11_reorg
254 #undef TARGET_INIT_LIBFUNCS
255 #define TARGET_INIT_LIBFUNCS m68hc11_init_libfuncs
257 #undef TARGET_STRUCT_VALUE_RTX
258 #define TARGET_STRUCT_VALUE_RTX m68hc11_struct_value_rtx
259 #undef TARGET_RETURN_IN_MEMORY
260 #define TARGET_RETURN_IN_MEMORY m68hc11_return_in_memory
261 #undef TARGET_CALLEE_COPIES
262 #define TARGET_CALLEE_COPIES hook_callee_copies_named
264 #undef TARGET_STRIP_NAME_ENCODING
265 #define TARGET_STRIP_NAME_ENCODING m68hc11_strip_name_encoding
267 struct gcc_target targetm
= TARGET_INITIALIZER
;
270 m68hc11_override_options (void)
272 memset (m68hc11_reg_valid_for_index
, 0,
273 sizeof (m68hc11_reg_valid_for_index
));
274 memset (m68hc11_reg_valid_for_base
, 0, sizeof (m68hc11_reg_valid_for_base
));
276 /* Compilation with -fpic generates a wrong code. */
279 warning (0, "-f%s ignored for 68HC11/68HC12 (not supported)",
280 (flag_pic
> 1) ? "PIC" : "pic");
284 /* Do not enable -fweb because it breaks the 32-bit shift patterns
285 by breaking the match_dup of those patterns. The shift patterns
286 will no longer be recognized after that. */
289 /* Configure for a 68hc11 processor. */
292 target_flags
&= ~(TARGET_AUTO_INC_DEC
| TARGET_MIN_MAX
);
293 m68hc11_cost
= &m6811_cost
;
294 m68hc11_min_offset
= 0;
295 m68hc11_max_offset
= 256;
296 m68hc11_index_reg_class
= NO_REGS
;
297 m68hc11_base_reg_class
= A_REGS
;
298 m68hc11_reg_valid_for_base
[HARD_X_REGNUM
] = 1;
299 m68hc11_reg_valid_for_base
[HARD_Y_REGNUM
] = 1;
300 m68hc11_reg_valid_for_base
[HARD_Z_REGNUM
] = 1;
301 m68hc11_sp_correction
= 1;
302 m68hc11_tmp_regs_class
= D_REGS
;
303 m68hc11_addr_mode
= ADDR_OFFSET
;
304 m68hc11_mov_addr_mode
= 0;
305 if (m68hc11_soft_reg_count
< 0)
306 m68hc11_soft_reg_count
= 4;
309 /* Configure for a 68hc12 processor. */
312 m68hc11_cost
= &m6812_cost
;
313 m68hc11_min_offset
= -65536;
314 m68hc11_max_offset
= 65536;
315 m68hc11_index_reg_class
= D_REGS
;
316 m68hc11_base_reg_class
= A_OR_SP_REGS
;
317 m68hc11_reg_valid_for_base
[HARD_X_REGNUM
] = 1;
318 m68hc11_reg_valid_for_base
[HARD_Y_REGNUM
] = 1;
319 m68hc11_reg_valid_for_base
[HARD_Z_REGNUM
] = 1;
320 m68hc11_reg_valid_for_base
[HARD_SP_REGNUM
] = 1;
321 m68hc11_reg_valid_for_index
[HARD_D_REGNUM
] = 1;
322 m68hc11_sp_correction
= 0;
323 m68hc11_tmp_regs_class
= TMP_REGS
;
324 m68hc11_addr_mode
= ADDR_INDIRECT
| ADDR_OFFSET
| ADDR_CONST
325 | (TARGET_AUTO_INC_DEC
? ADDR_INCDEC
: 0);
326 m68hc11_mov_addr_mode
= ADDR_OFFSET
| ADDR_CONST
327 | (TARGET_AUTO_INC_DEC
? ADDR_INCDEC
: 0);
328 target_flags
|= MASK_NO_DIRECT_MODE
;
329 if (m68hc11_soft_reg_count
< 0)
330 m68hc11_soft_reg_count
= 0;
332 if (TARGET_LONG_CALLS
)
333 current_function_far
= 1;
340 m68hc11_conditional_register_usage (void)
344 if (m68hc11_soft_reg_count
> SOFT_REG_LAST
- SOFT_REG_FIRST
)
345 m68hc11_soft_reg_count
= SOFT_REG_LAST
- SOFT_REG_FIRST
;
347 for (i
= SOFT_REG_FIRST
+ m68hc11_soft_reg_count
; i
< SOFT_REG_LAST
; i
++)
350 call_used_regs
[i
] = 1;
353 /* For 68HC12, the Z register emulation is not necessary when the
354 frame pointer is not used. The frame pointer is eliminated and
355 replaced by the stack register (which is a BASE_REG_CLASS). */
356 if (TARGET_M6812
&& flag_omit_frame_pointer
&& optimize
)
358 fixed_regs
[HARD_Z_REGNUM
] = 1;
363 /* Reload and register operations. */
367 create_regs_rtx (void)
369 /* regs_inited = 1; */
370 ix_reg
= gen_rtx_REG (HImode
, HARD_X_REGNUM
);
371 iy_reg
= gen_rtx_REG (HImode
, HARD_Y_REGNUM
);
372 d_reg
= gen_rtx_REG (HImode
, HARD_D_REGNUM
);
373 m68hc11_soft_tmp_reg
= gen_rtx_REG (HImode
, SOFT_TMP_REGNUM
);
375 stack_push_word
= gen_rtx_MEM (HImode
,
376 gen_rtx_PRE_DEC (HImode
,
377 gen_rtx_REG (HImode
, HARD_SP_REGNUM
)));
378 stack_pop_word
= gen_rtx_MEM (HImode
,
379 gen_rtx_POST_INC (HImode
,
380 gen_rtx_REG (HImode
, HARD_SP_REGNUM
)));
384 /* Value is 1 if hard register REGNO can hold a value of machine-mode MODE.
385 - 8 bit values are stored anywhere (except the SP register).
386 - 16 bit values can be stored in any register whose mode is 16
387 - 32 bit values can be stored in D, X registers or in a soft register
388 (except the last one because we need 2 soft registers)
389 - Values whose size is > 32 bit are not stored in real hard
390 registers. They may be stored in soft registers if there are
393 hard_regno_mode_ok (int regno
, enum machine_mode mode
)
395 switch (GET_MODE_SIZE (mode
))
398 return S_REGNO_P (regno
) && m68hc11_soft_reg_count
>= 4;
401 return (X_REGNO_P (regno
)
402 || (S_REGNO_P (regno
) && m68hc11_soft_reg_count
>= 2));
405 return G_REGNO_P (regno
);
408 /* We have to accept a QImode in X or Y registers. Otherwise, the
409 reload pass will fail when some (SUBREG:QI (REG:HI X)) are defined
410 in the insns. Reload fails if the insn rejects the register class 'a'
411 as well as if it accepts it. Patterns that failed were
412 zero_extend_qihi2 and iorqi3. */
414 return G_REGNO_P (regno
) && !SP_REGNO_P (regno
);
422 m68hc11_hard_regno_rename_ok (int reg1
, int reg2
)
424 /* Don't accept renaming to Z register. We will replace it to
425 X,Y or D during machine reorg pass. */
426 if (reg2
== HARD_Z_REGNUM
)
429 /* Don't accept renaming D,X to Y register as the code will be bigger. */
430 if (TARGET_M6811
&& reg2
== HARD_Y_REGNUM
431 && (D_REGNO_P (reg1
) || X_REGNO_P (reg1
)))
438 preferred_reload_class (rtx operand
, enum reg_class
class)
440 enum machine_mode mode
;
442 mode
= GET_MODE (operand
);
446 printf ("Preferred reload: (class=%s): ", reg_class_names
[class]);
449 if (class == D_OR_A_OR_S_REGS
&& SP_REG_P (operand
))
450 return m68hc11_base_reg_class
;
452 if (class >= S_REGS
&& (GET_CODE (operand
) == MEM
453 || GET_CODE (operand
) == CONST_INT
))
455 /* S_REGS class must not be used. The movhi template does not
456 work to move a memory to a soft register.
457 Restrict to a hard reg. */
462 case D_OR_A_OR_S_REGS
:
468 case D_OR_SP_OR_S_REGS
:
469 class = D_OR_SP_REGS
;
471 case D_OR_Y_OR_S_REGS
:
474 case D_OR_X_OR_S_REGS
:
490 else if (class == Y_REGS
&& GET_CODE (operand
) == MEM
)
494 else if (class == A_OR_D_REGS
&& GET_MODE_SIZE (mode
) == 4)
498 else if (class >= S_REGS
&& S_REG_P (operand
))
504 case D_OR_A_OR_S_REGS
:
510 case D_OR_SP_OR_S_REGS
:
511 class = D_OR_SP_REGS
;
513 case D_OR_Y_OR_S_REGS
:
516 case D_OR_X_OR_S_REGS
:
532 else if (class >= S_REGS
)
536 printf ("Class = %s for: ", reg_class_names
[class]);
544 printf (" => class=%s\n", reg_class_names
[class]);
552 /* Return 1 if the operand is a valid indexed addressing mode.
553 For 68hc11: n,r with n in [0..255] and r in A_REGS class
554 For 68hc12: n,r no constraint on the constant, r in A_REGS class. */
556 m68hc11_valid_addressing_p (rtx operand
, enum machine_mode mode
, int addr_mode
)
560 switch (GET_CODE (operand
))
563 if ((addr_mode
& ADDR_INDIRECT
) && GET_MODE_SIZE (mode
) <= 2)
564 return m68hc11_valid_addressing_p (XEXP (operand
, 0), mode
,
565 addr_mode
& (ADDR_STRICT
| ADDR_OFFSET
));
572 if (addr_mode
& ADDR_INCDEC
)
573 return m68hc11_valid_addressing_p (XEXP (operand
, 0), mode
,
574 addr_mode
& ADDR_STRICT
);
578 base
= XEXP (operand
, 0);
579 if (GET_CODE (base
) == MEM
)
582 offset
= XEXP (operand
, 1);
583 if (GET_CODE (offset
) == MEM
)
586 /* Indexed addressing mode with 2 registers. */
587 if (GET_CODE (base
) == REG
&& GET_CODE (offset
) == REG
)
589 if (!(addr_mode
& ADDR_INDEXED
))
592 addr_mode
&= ADDR_STRICT
;
593 if (REGNO_OK_FOR_BASE_P2 (REGNO (base
), addr_mode
)
594 && REGNO_OK_FOR_INDEX_P2 (REGNO (offset
), addr_mode
))
597 if (REGNO_OK_FOR_BASE_P2 (REGNO (offset
), addr_mode
)
598 && REGNO_OK_FOR_INDEX_P2 (REGNO (base
), addr_mode
))
604 if (!(addr_mode
& ADDR_OFFSET
))
607 if (GET_CODE (base
) == REG
)
609 if (!VALID_CONSTANT_OFFSET_P (offset
, mode
))
612 if (!(addr_mode
& ADDR_STRICT
))
615 return REGNO_OK_FOR_BASE_P2 (REGNO (base
), 1);
618 if (GET_CODE (offset
) == REG
)
620 if (!VALID_CONSTANT_OFFSET_P (base
, mode
))
623 if (!(addr_mode
& ADDR_STRICT
))
626 return REGNO_OK_FOR_BASE_P2 (REGNO (offset
), 1);
631 return REGNO_OK_FOR_BASE_P2 (REGNO (operand
), addr_mode
& ADDR_STRICT
);
634 if (addr_mode
& ADDR_CONST
)
635 return VALID_CONSTANT_OFFSET_P (operand
, mode
);
643 /* Returns 1 if the operand fits in a 68HC11 indirect mode or in
644 a 68HC12 1-byte index addressing mode. */
646 m68hc11_small_indexed_indirect_p (rtx operand
, enum machine_mode mode
)
651 if (GET_CODE (operand
) == REG
&& reload_in_progress
652 && REGNO (operand
) >= FIRST_PSEUDO_REGISTER
653 && reg_equiv_memory_loc
[REGNO (operand
)])
655 operand
= reg_equiv_memory_loc
[REGNO (operand
)];
656 operand
= eliminate_regs (operand
, 0, NULL_RTX
);
659 if (GET_CODE (operand
) != MEM
)
662 operand
= XEXP (operand
, 0);
663 if (CONSTANT_ADDRESS_P (operand
))
666 if (PUSH_POP_ADDRESS_P (operand
))
669 addr_mode
= m68hc11_mov_addr_mode
| (reload_completed
? ADDR_STRICT
: 0);
670 if (!m68hc11_valid_addressing_p (operand
, mode
, addr_mode
))
673 if (TARGET_M6812
&& GET_CODE (operand
) == PLUS
674 && (reload_completed
| reload_in_progress
))
676 base
= XEXP (operand
, 0);
677 offset
= XEXP (operand
, 1);
679 /* The offset can be a symbol address and this is too big
680 for the operand constraint. */
681 if (GET_CODE (base
) != CONST_INT
&& GET_CODE (offset
) != CONST_INT
)
684 if (GET_CODE (base
) == CONST_INT
)
687 switch (GET_MODE_SIZE (mode
))
690 if (INTVAL (offset
) < -16 + 6 || INTVAL (offset
) > 15 - 6)
695 if (INTVAL (offset
) < -16 + 2 || INTVAL (offset
) > 15 - 2)
700 if (INTVAL (offset
) < -16 || INTVAL (offset
) > 15)
709 m68hc11_register_indirect_p (rtx operand
, enum machine_mode mode
)
713 if (GET_CODE (operand
) == REG
&& reload_in_progress
714 && REGNO (operand
) >= FIRST_PSEUDO_REGISTER
715 && reg_equiv_memory_loc
[REGNO (operand
)])
717 operand
= reg_equiv_memory_loc
[REGNO (operand
)];
718 operand
= eliminate_regs (operand
, 0, NULL_RTX
);
720 if (GET_CODE (operand
) != MEM
)
723 operand
= XEXP (operand
, 0);
724 addr_mode
= m68hc11_addr_mode
| (reload_completed
? ADDR_STRICT
: 0);
725 return m68hc11_valid_addressing_p (operand
, mode
, addr_mode
);
729 go_if_legitimate_address_internal (rtx operand
, enum machine_mode mode
,
734 if (CONSTANT_ADDRESS_P (operand
) && TARGET_M6812
)
736 /* Reject the global variables if they are too wide. This forces
737 a load of their address in a register and generates smaller code. */
738 if (GET_MODE_SIZE (mode
) == 8)
743 addr_mode
= m68hc11_addr_mode
| (strict
? ADDR_STRICT
: 0);
744 if (m68hc11_valid_addressing_p (operand
, mode
, addr_mode
))
748 if (PUSH_POP_ADDRESS_P (operand
))
752 if (symbolic_memory_operand (operand
, mode
))
760 m68hc11_go_if_legitimate_address (rtx operand
, enum machine_mode mode
,
767 printf ("Checking: ");
772 result
= go_if_legitimate_address_internal (operand
, mode
, strict
);
776 printf (" -> %s\n", result
== 0 ? "NO" : "YES");
783 printf ("go_if_legitimate%s, ret 0: %d:",
784 (strict
? "_strict" : ""), mode
);
793 m68hc11_legitimize_address (rtx
*operand ATTRIBUTE_UNUSED
,
794 rtx old_operand ATTRIBUTE_UNUSED
,
795 enum machine_mode mode ATTRIBUTE_UNUSED
)
802 m68hc11_reload_operands (rtx operands
[])
804 enum machine_mode mode
;
806 if (regs_inited
== 0)
809 mode
= GET_MODE (operands
[1]);
811 /* Input reload of indirect addressing (MEM (PLUS (REG) (CONST))). */
812 if (A_REG_P (operands
[0]) && memory_reload_operand (operands
[1], mode
))
814 rtx big_offset
= XEXP (XEXP (operands
[1], 0), 1);
815 rtx base
= XEXP (XEXP (operands
[1], 0), 0);
817 if (GET_CODE (base
) != REG
)
824 /* If the offset is out of range, we have to compute the address
825 with a separate add instruction. We try to do with with an 8-bit
826 add on the A register. This is possible only if the lowest part
827 of the offset (i.e., big_offset % 256) is a valid constant offset
828 with respect to the mode. If it's not, we have to generate a
829 16-bit add on the D register. From:
831 (SET (REG X (MEM (PLUS (REG X) (CONST_INT 1000)))))
835 [(SET (REG D) (REG X)) (SET (REG X) (REG D))]
836 (SET (REG A) (PLUS (REG A) (CONST_INT 1000 / 256)))
837 [(SET (REG D) (REG X)) (SET (REG X) (REG D))]
838 (SET (REG X) (MEM (PLUS (REG X) (CONST_INT 1000 % 256)))
840 (SET (REG X) (PLUS (REG X) (CONST_INT 1000 / 256 * 256)))
841 (SET (REG X) (MEM (PLUS (REG X) (CONST_INT 1000 % 256))))
844 if (!VALID_CONSTANT_OFFSET_P (big_offset
, mode
))
847 rtx reg
= operands
[0];
849 int val
= INTVAL (big_offset
);
852 /* We use the 'operands[0]' as a scratch register to compute the
853 address. Make sure 'base' is in that register. */
854 if (!rtx_equal_p (base
, operands
[0]))
856 emit_move_insn (reg
, base
);
866 vh
= (val
>> 8) & 0x0FF;
870 /* Create the lowest part offset that still remains to be added.
871 If it's not a valid offset, do a 16-bit add. */
872 offset
= GEN_INT (vl
);
873 if (!VALID_CONSTANT_OFFSET_P (offset
, mode
))
875 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
876 gen_rtx_PLUS (HImode
, reg
, big_offset
)));
881 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
882 gen_rtx_PLUS (HImode
, reg
,
883 GEN_INT (vh
<< 8))));
885 emit_move_insn (operands
[0],
886 gen_rtx_MEM (GET_MODE (operands
[1]),
887 gen_rtx_PLUS (Pmode
, reg
, offset
)));
892 /* Use the normal gen_movhi pattern. */
897 m68hc11_emit_libcall (const char *name
, enum rtx_code code
,
898 enum machine_mode dmode
, enum machine_mode smode
,
899 int noperands
, rtx
*operands
)
907 libcall
= gen_rtx_SYMBOL_REF (Pmode
, name
);
911 ret
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
,
912 dmode
, 1, operands
[1], smode
);
913 equiv
= gen_rtx_fmt_e (code
, dmode
, operands
[1]);
917 ret
= emit_library_call_value (libcall
, NULL_RTX
,
919 operands
[1], smode
, operands
[2],
921 equiv
= gen_rtx_fmt_ee (code
, dmode
, operands
[1], operands
[2]);
928 insns
= get_insns ();
930 emit_libcall_block (insns
, operands
[0], ret
, equiv
);
933 /* Returns true if X is a PRE/POST increment decrement
934 (same as auto_inc_p() in rtlanal.c but do not take into
935 account the stack). */
937 m68hc11_auto_inc_p (rtx x
)
939 return GET_CODE (x
) == PRE_DEC
940 || GET_CODE (x
) == POST_INC
941 || GET_CODE (x
) == POST_DEC
|| GET_CODE (x
) == PRE_INC
;
945 /* Predicates for machine description. */
948 memory_reload_operand (rtx operand
, enum machine_mode mode ATTRIBUTE_UNUSED
)
950 return GET_CODE (operand
) == MEM
951 && GET_CODE (XEXP (operand
, 0)) == PLUS
952 && ((GET_CODE (XEXP (XEXP (operand
, 0), 0)) == REG
953 && GET_CODE (XEXP (XEXP (operand
, 0), 1)) == CONST_INT
)
954 || (GET_CODE (XEXP (XEXP (operand
, 0), 1)) == REG
955 && GET_CODE (XEXP (XEXP (operand
, 0), 0)) == CONST_INT
));
959 m68hc11_symbolic_p (rtx operand
, enum machine_mode mode
)
961 if (GET_CODE (operand
) == MEM
)
963 rtx op
= XEXP (operand
, 0);
965 if (symbolic_memory_operand (op
, mode
))
972 m68hc11_indirect_p (rtx operand
, enum machine_mode mode
)
974 if (GET_CODE (operand
) == MEM
&& GET_MODE (operand
) == mode
)
976 rtx op
= XEXP (operand
, 0);
979 if (m68hc11_page0_symbol_p (op
))
982 if (symbolic_memory_operand (op
, mode
))
985 if (reload_in_progress
)
988 operand
= XEXP (operand
, 0);
989 addr_mode
= m68hc11_addr_mode
| (reload_completed
? ADDR_STRICT
: 0);
990 return m68hc11_valid_addressing_p (operand
, mode
, addr_mode
);
996 memory_indexed_operand (rtx operand
, enum machine_mode mode ATTRIBUTE_UNUSED
)
998 if (GET_CODE (operand
) != MEM
)
1001 operand
= XEXP (operand
, 0);
1002 if (GET_CODE (operand
) == PLUS
)
1004 if (GET_CODE (XEXP (operand
, 0)) == REG
)
1005 operand
= XEXP (operand
, 0);
1006 else if (GET_CODE (XEXP (operand
, 1)) == REG
)
1007 operand
= XEXP (operand
, 1);
1009 return GET_CODE (operand
) == REG
1010 && (REGNO (operand
) >= FIRST_PSEUDO_REGISTER
1011 || A_REGNO_P (REGNO (operand
)));
1015 push_pop_operand_p (rtx operand
)
1017 if (GET_CODE (operand
) != MEM
)
1021 operand
= XEXP (operand
, 0);
1022 return PUSH_POP_ADDRESS_P (operand
);
1025 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
1026 reference and a constant. */
1029 symbolic_memory_operand (rtx op
, enum machine_mode mode
)
1031 switch (GET_CODE (op
))
1039 return ((GET_CODE (XEXP (op
, 0)) == SYMBOL_REF
1040 || GET_CODE (XEXP (op
, 0)) == LABEL_REF
)
1041 && GET_CODE (XEXP (op
, 1)) == CONST_INT
);
1043 /* ??? This clause seems to be irrelevant. */
1045 return GET_MODE (op
) == mode
;
1048 return symbolic_memory_operand (XEXP (op
, 0), mode
)
1049 && symbolic_memory_operand (XEXP (op
, 1), mode
);
1056 /* Emit the code to build the trampoline used to call a nested function.
1060 ldy #&CXT movw #&CXT,*_.d1
1061 sty *_.d1 jmp FNADDR
1066 m68hc11_initialize_trampoline (rtx tramp
, rtx fnaddr
, rtx cxt
)
1068 const char *static_chain_reg
= reg_names
[STATIC_CHAIN_REGNUM
];
1071 if (*static_chain_reg
== '*')
1075 emit_move_insn (gen_rtx_MEM (HImode
, tramp
), GEN_INT (0x18ce));
1076 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 2)), cxt
);
1077 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 4)),
1079 emit_move_insn (gen_rtx_MEM (QImode
, plus_constant (tramp
, 6)),
1080 gen_rtx_CONST (QImode
,
1081 gen_rtx_SYMBOL_REF (Pmode
,
1082 static_chain_reg
)));
1083 emit_move_insn (gen_rtx_MEM (QImode
, plus_constant (tramp
, 7)),
1085 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 8)), fnaddr
);
1089 emit_move_insn (gen_rtx_MEM (HImode
, tramp
), GEN_INT (0x1803));
1090 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 2)), cxt
);
1091 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 4)),
1092 gen_rtx_CONST (HImode
,
1093 gen_rtx_SYMBOL_REF (Pmode
,
1094 static_chain_reg
)));
1095 emit_move_insn (gen_rtx_MEM (QImode
, plus_constant (tramp
, 6)),
1097 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 7)), fnaddr
);
1101 /* Declaration of types. */
1103 /* Handle an "tiny_data" attribute; arguments as in
1104 struct attribute_spec.handler. */
1106 m68hc11_handle_page0_attribute (tree
*node
, tree name
,
1107 tree args ATTRIBUTE_UNUSED
,
1108 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
1112 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
1114 DECL_SECTION_NAME (decl
) = build_string (6, ".page0");
1118 warning (OPT_Wattributes
, "%qs attribute ignored",
1119 IDENTIFIER_POINTER (name
));
1120 *no_add_attrs
= true;
1126 const struct attribute_spec m68hc11_attribute_table
[] =
1128 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
1129 { "interrupt", 0, 0, false, true, true, m68hc11_handle_fntype_attribute
},
1130 { "trap", 0, 0, false, true, true, m68hc11_handle_fntype_attribute
},
1131 { "far", 0, 0, false, true, true, m68hc11_handle_fntype_attribute
},
1132 { "near", 0, 0, false, true, true, m68hc11_handle_fntype_attribute
},
1133 { "page0", 0, 0, false, false, false, m68hc11_handle_page0_attribute
},
1134 { NULL
, 0, 0, false, false, false, NULL
}
1137 /* Keep track of the symbol which has a `trap' attribute and which uses
1138 the `swi' calling convention. Since there is only one trap, we only
1139 record one such symbol. If there are several, a warning is reported. */
1140 static rtx trap_handler_symbol
= 0;
1142 /* Handle an attribute requiring a FUNCTION_TYPE, FIELD_DECL or TYPE_DECL;
1143 arguments as in struct attribute_spec.handler. */
1145 m68hc11_handle_fntype_attribute (tree
*node
, tree name
,
1146 tree args ATTRIBUTE_UNUSED
,
1147 int flags ATTRIBUTE_UNUSED
,
1150 if (TREE_CODE (*node
) != FUNCTION_TYPE
1151 && TREE_CODE (*node
) != METHOD_TYPE
1152 && TREE_CODE (*node
) != FIELD_DECL
1153 && TREE_CODE (*node
) != TYPE_DECL
)
1155 warning (OPT_Wattributes
, "%qs attribute only applies to functions",
1156 IDENTIFIER_POINTER (name
));
1157 *no_add_attrs
= true;
1162 /* Undo the effects of the above. */
1165 m68hc11_strip_name_encoding (const char *str
)
1167 return str
+ (*str
== '*' || *str
== '@' || *str
== '&');
1171 m68hc11_encode_label (tree decl
)
1173 const char *str
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1174 int len
= strlen (str
);
1175 char *newstr
= alloca (len
+ 2);
1178 strcpy (&newstr
[1], str
);
1180 XSTR (XEXP (DECL_RTL (decl
), 0), 0) = ggc_alloc_string (newstr
, len
+ 1);
1183 /* Return 1 if this is a symbol in page0 */
1185 m68hc11_page0_symbol_p (rtx x
)
1187 switch (GET_CODE (x
))
1190 return XSTR (x
, 0) != 0 && XSTR (x
, 0)[0] == '@';
1193 return m68hc11_page0_symbol_p (XEXP (x
, 0));
1196 if (!m68hc11_page0_symbol_p (XEXP (x
, 0)))
1199 return GET_CODE (XEXP (x
, 1)) == CONST_INT
1200 && INTVAL (XEXP (x
, 1)) < 256
1201 && INTVAL (XEXP (x
, 1)) >= 0;
1208 /* We want to recognize trap handlers so that we handle calls to traps
1209 in a special manner (by issuing the trap). This information is stored
1210 in SYMBOL_REF_FLAG. */
1213 m68hc11_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
1219 if (TREE_CODE (decl
) == VAR_DECL
)
1221 if (lookup_attribute ("page0", DECL_ATTRIBUTES (decl
)) != 0)
1222 m68hc11_encode_label (decl
);
1226 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1229 func_attr
= TYPE_ATTRIBUTES (TREE_TYPE (decl
));
1232 if (lookup_attribute ("far", func_attr
) != NULL_TREE
)
1234 else if (lookup_attribute ("near", func_attr
) == NULL_TREE
)
1235 is_far
= TARGET_LONG_CALLS
!= 0;
1237 trap_handler
= lookup_attribute ("trap", func_attr
) != NULL_TREE
;
1238 if (trap_handler
&& is_far
)
1240 warning (OPT_Wattributes
, "%<trap%> and %<far%> attributes are "
1241 "not compatible, ignoring %<far%>");
1246 if (trap_handler_symbol
!= 0)
1247 warning (OPT_Wattributes
, "%<trap%> attribute is already used");
1249 trap_handler_symbol
= XEXP (rtl
, 0);
1251 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = is_far
;
1255 m68hc11_section_type_flags (tree decl
, const char *name
, int reloc
)
1257 unsigned int flags
= default_section_type_flags (decl
, name
, reloc
);
1259 if (strncmp (name
, ".eeprom", 7) == 0)
1261 flags
|= SECTION_WRITE
| SECTION_CODE
| SECTION_OVERRIDE
;
1268 m68hc11_is_far_symbol (rtx sym
)
1270 if (GET_CODE (sym
) == MEM
)
1271 sym
= XEXP (sym
, 0);
1273 return SYMBOL_REF_FLAG (sym
);
1277 m68hc11_is_trap_symbol (rtx sym
)
1279 if (GET_CODE (sym
) == MEM
)
1280 sym
= XEXP (sym
, 0);
1282 return trap_handler_symbol
!= 0 && rtx_equal_p (trap_handler_symbol
, sym
);
1286 /* Argument support functions. */
1288 /* Define the offset between two registers, one to be eliminated, and the
1289 other its replacement, at the start of a routine. */
1291 m68hc11_initial_elimination_offset (int from
, int to
)
1298 /* For a trap handler, we must take into account the registers which
1299 are pushed on the stack during the trap (except the PC). */
1300 func_attr
= TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl
));
1301 current_function_interrupt
= lookup_attribute ("interrupt",
1302 func_attr
) != NULL_TREE
;
1303 trap_handler
= lookup_attribute ("trap", func_attr
) != NULL_TREE
;
1305 if (lookup_attribute ("far", func_attr
) != 0)
1306 current_function_far
= 1;
1307 else if (lookup_attribute ("near", func_attr
) != 0)
1308 current_function_far
= 0;
1310 current_function_far
= (TARGET_LONG_CALLS
!= 0
1311 && !current_function_interrupt
1314 if (trap_handler
&& from
== ARG_POINTER_REGNUM
)
1317 /* For a function using 'call/rtc' we must take into account the
1318 page register which is pushed in the call. */
1319 else if (current_function_far
&& from
== ARG_POINTER_REGNUM
)
1324 if (from
== ARG_POINTER_REGNUM
&& to
== HARD_FRAME_POINTER_REGNUM
)
1326 /* 2 is for the saved frame.
1327 1 is for the 'sts' correction when creating the frame. */
1328 return get_frame_size () + 2 + m68hc11_sp_correction
+ size
;
1331 if (from
== FRAME_POINTER_REGNUM
&& to
== HARD_FRAME_POINTER_REGNUM
)
1333 return m68hc11_sp_correction
;
1336 /* Push any 2 byte pseudo hard registers that we need to save. */
1337 for (regno
= SOFT_REG_FIRST
; regno
< SOFT_REG_LAST
; regno
++)
1339 if (regs_ever_live
[regno
] && !call_used_regs
[regno
])
1345 if (from
== ARG_POINTER_REGNUM
&& to
== HARD_SP_REGNUM
)
1347 return get_frame_size () + size
;
1350 if (from
== FRAME_POINTER_REGNUM
&& to
== HARD_SP_REGNUM
)
1357 /* Initialize a variable CUM of type CUMULATIVE_ARGS
1358 for a call to a function whose data type is FNTYPE.
1359 For a library call, FNTYPE is 0. */
1362 m68hc11_init_cumulative_args (CUMULATIVE_ARGS
*cum
, tree fntype
, rtx libname
)
1366 z_replacement_completed
= 0;
1370 /* For a library call, we must find out the type of the return value.
1371 When the return value is bigger than 4 bytes, it is returned in
1372 memory. In that case, the first argument of the library call is a
1373 pointer to the memory location. Because the first argument is passed in
1374 register D, we have to identify this, so that the first function
1375 parameter is not passed in D either. */
1381 if (libname
== 0 || GET_CODE (libname
) != SYMBOL_REF
)
1384 /* If the library ends in 'di' or in 'df', we assume it's
1385 returning some DImode or some DFmode which are 64-bit wide. */
1386 name
= XSTR (libname
, 0);
1387 len
= strlen (name
);
1389 && ((name
[len
- 2] == 'd'
1390 && (name
[len
- 1] == 'f' || name
[len
- 1] == 'i'))
1391 || (name
[len
- 3] == 'd'
1392 && (name
[len
- 2] == 'i' || name
[len
- 2] == 'f'))))
1394 /* We are in. Mark the first parameter register as already used. */
1401 ret_type
= TREE_TYPE (fntype
);
1403 if (ret_type
&& aggregate_value_p (ret_type
, fntype
))
1410 /* Update the data in CUM to advance over an argument
1411 of mode MODE and data type TYPE.
1412 (TYPE is null for libcalls where that information may not be available.) */
1415 m68hc11_function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
1416 tree type
, int named ATTRIBUTE_UNUSED
)
1418 if (mode
!= BLKmode
)
1420 if (cum
->words
== 0 && GET_MODE_SIZE (mode
) == 4)
1423 cum
->words
= GET_MODE_SIZE (mode
);
1427 cum
->words
+= GET_MODE_SIZE (mode
);
1428 if (cum
->words
<= HARD_REG_SIZE
)
1434 cum
->words
+= int_size_in_bytes (type
);
1439 /* Define where to put the arguments to a function.
1440 Value is zero to push the argument on the stack,
1441 or a hard register in which to store the argument.
1443 MODE is the argument's machine mode.
1444 TYPE is the data type of the argument (as a tree).
1445 This is null for libcalls where that information may
1447 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1448 the preceding args and about the function being called.
1449 NAMED is nonzero if this argument is a named parameter
1450 (otherwise it is an extra parameter matching an ellipsis). */
1453 m68hc11_function_arg (const CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
1454 tree type ATTRIBUTE_UNUSED
, int named ATTRIBUTE_UNUSED
)
1456 if (cum
->words
!= 0)
1461 if (mode
!= BLKmode
)
1463 if (GET_MODE_SIZE (mode
) == 2 * HARD_REG_SIZE
)
1464 return gen_rtx_REG (mode
, HARD_X_REGNUM
);
1466 if (GET_MODE_SIZE (mode
) > HARD_REG_SIZE
)
1470 return gen_rtx_REG (mode
, HARD_D_REGNUM
);
1475 /* If defined, a C expression which determines whether, and in which direction,
1476 to pad out an argument with extra space. The value should be of type
1477 `enum direction': either `upward' to pad above the argument,
1478 `downward' to pad below, or `none' to inhibit padding.
1480 Structures are stored left shifted in their argument slot. */
1482 m68hc11_function_arg_padding (enum machine_mode mode
, tree type
)
1484 if (type
!= 0 && AGGREGATE_TYPE_P (type
))
1487 /* Fall back to the default. */
1488 return DEFAULT_FUNCTION_ARG_PADDING (mode
, type
);
1492 /* Function prologue and epilogue. */
1494 /* Emit a move after the reload pass has completed. This is used to
1495 emit the prologue and epilogue. */
1497 emit_move_after_reload (rtx to
, rtx from
, rtx scratch
)
1501 if (TARGET_M6812
|| H_REG_P (to
) || H_REG_P (from
))
1503 insn
= emit_move_insn (to
, from
);
1507 emit_move_insn (scratch
, from
);
1508 insn
= emit_move_insn (to
, scratch
);
1511 /* Put a REG_INC note to tell the flow analysis that the instruction
1513 if (IS_STACK_PUSH (to
))
1515 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_INC
,
1516 XEXP (XEXP (to
, 0), 0),
1519 else if (IS_STACK_POP (from
))
1521 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_INC
,
1522 XEXP (XEXP (from
, 0), 0),
1526 /* For 68HC11, put a REG_INC note on `sts _.frame' to prevent the cse-reg
1527 to think that sp == _.frame and later replace a x = sp with x = _.frame.
1528 The problem is that we are lying to gcc and use `txs' for x = sp
1529 (which is not really true because txs is really x = sp + 1). */
1530 else if (TARGET_M6811
&& SP_REG_P (from
))
1532 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_INC
,
1539 m68hc11_total_frame_size (void)
1544 size
= get_frame_size ();
1545 if (current_function_interrupt
)
1547 size
+= 3 * HARD_REG_SIZE
;
1549 if (frame_pointer_needed
)
1550 size
+= HARD_REG_SIZE
;
1552 for (regno
= SOFT_REG_FIRST
; regno
<= SOFT_REG_LAST
; regno
++)
1553 if (regs_ever_live
[regno
] && !call_used_regs
[regno
])
1554 size
+= HARD_REG_SIZE
;
1560 m68hc11_output_function_epilogue (FILE *out ATTRIBUTE_UNUSED
,
1561 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
1563 /* We catch the function epilogue generation to have a chance
1564 to clear the z_replacement_completed flag. */
1565 z_replacement_completed
= 0;
1569 expand_prologue (void)
1576 gcc_assert (reload_completed
== 1);
1578 size
= get_frame_size ();
1582 /* Generate specific prologue for interrupt handlers. */
1583 func_attr
= TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl
));
1584 current_function_interrupt
= lookup_attribute ("interrupt",
1585 func_attr
) != NULL_TREE
;
1586 current_function_trap
= lookup_attribute ("trap", func_attr
) != NULL_TREE
;
1587 if (lookup_attribute ("far", func_attr
) != NULL_TREE
)
1588 current_function_far
= 1;
1589 else if (lookup_attribute ("near", func_attr
) != NULL_TREE
)
1590 current_function_far
= 0;
1592 current_function_far
= (TARGET_LONG_CALLS
!= 0
1593 && !current_function_interrupt
1594 && !current_function_trap
);
1596 /* Get the scratch register to build the frame and push registers.
1597 If the first argument is a 32-bit quantity, the D+X registers
1598 are used. Use Y to compute the frame. Otherwise, X is cheaper.
1599 For 68HC12, this scratch register is not used. */
1600 if (current_function_args_info
.nregs
== 2)
1605 /* Save current stack frame. */
1606 if (frame_pointer_needed
)
1607 emit_move_after_reload (stack_push_word
, hard_frame_pointer_rtx
, scratch
);
1609 /* For an interrupt handler, we must preserve _.tmp, _.z and _.xy.
1610 Other soft registers in page0 need not to be saved because they
1611 will be restored by C functions. For a trap handler, we don't
1612 need to preserve these registers because this is a synchronous call. */
1613 if (current_function_interrupt
)
1615 emit_move_after_reload (stack_push_word
, m68hc11_soft_tmp_reg
, scratch
);
1616 emit_move_after_reload (stack_push_word
,
1617 gen_rtx_REG (HImode
, SOFT_Z_REGNUM
), scratch
);
1618 emit_move_after_reload (stack_push_word
,
1619 gen_rtx_REG (HImode
, SOFT_SAVED_XY_REGNUM
),
1623 /* Allocate local variables. */
1624 if (TARGET_M6812
&& (size
> 4 || size
== 3))
1626 emit_insn (gen_addhi3 (stack_pointer_rtx
,
1627 stack_pointer_rtx
, GEN_INT (-size
)));
1629 else if ((!optimize_size
&& size
> 8) || (optimize_size
&& size
> 10))
1633 insn
= gen_rtx_PARALLEL
1636 gen_rtx_SET (VOIDmode
,
1638 gen_rtx_PLUS (HImode
,
1641 gen_rtx_CLOBBER (VOIDmode
, scratch
)));
1648 /* Allocate by pushing scratch values. */
1649 for (i
= 2; i
<= size
; i
+= 2)
1650 emit_move_after_reload (stack_push_word
, ix_reg
, 0);
1653 emit_insn (gen_addhi3 (stack_pointer_rtx
,
1654 stack_pointer_rtx
, constm1_rtx
));
1657 /* Create the frame pointer. */
1658 if (frame_pointer_needed
)
1659 emit_move_after_reload (hard_frame_pointer_rtx
,
1660 stack_pointer_rtx
, scratch
);
1662 /* Push any 2 byte pseudo hard registers that we need to save. */
1663 for (regno
= SOFT_REG_FIRST
; regno
<= SOFT_REG_LAST
; regno
++)
1665 if (regs_ever_live
[regno
] && !call_used_regs
[regno
])
1667 emit_move_after_reload (stack_push_word
,
1668 gen_rtx_REG (HImode
, regno
), scratch
);
1674 expand_epilogue (void)
1681 gcc_assert (reload_completed
== 1);
1683 size
= get_frame_size ();
1685 /* If we are returning a value in two registers, we have to preserve the
1686 X register and use the Y register to restore the stack and the saved
1687 registers. Otherwise, use X because it's faster (and smaller). */
1688 if (current_function_return_rtx
== 0)
1690 else if (GET_CODE (current_function_return_rtx
) == MEM
)
1691 return_size
= HARD_REG_SIZE
;
1693 return_size
= GET_MODE_SIZE (GET_MODE (current_function_return_rtx
));
1695 if (return_size
> HARD_REG_SIZE
&& return_size
<= 2 * HARD_REG_SIZE
)
1700 /* Pop any 2 byte pseudo hard registers that we saved. */
1701 for (regno
= SOFT_REG_LAST
; regno
>= SOFT_REG_FIRST
; regno
--)
1703 if (regs_ever_live
[regno
] && !call_used_regs
[regno
])
1705 emit_move_after_reload (gen_rtx_REG (HImode
, regno
),
1706 stack_pop_word
, scratch
);
1710 /* de-allocate auto variables */
1711 if (TARGET_M6812
&& (size
> 4 || size
== 3))
1713 emit_insn (gen_addhi3 (stack_pointer_rtx
,
1714 stack_pointer_rtx
, GEN_INT (size
)));
1716 else if ((!optimize_size
&& size
> 8) || (optimize_size
&& size
> 10))
1720 insn
= gen_rtx_PARALLEL
1723 gen_rtx_SET (VOIDmode
,
1725 gen_rtx_PLUS (HImode
,
1728 gen_rtx_CLOBBER (VOIDmode
, scratch
)));
1735 for (i
= 2; i
<= size
; i
+= 2)
1736 emit_move_after_reload (scratch
, stack_pop_word
, scratch
);
1738 emit_insn (gen_addhi3 (stack_pointer_rtx
,
1739 stack_pointer_rtx
, const1_rtx
));
1742 /* For an interrupt handler, restore ZTMP, ZREG and XYREG. */
1743 if (current_function_interrupt
)
1745 emit_move_after_reload (gen_rtx_REG (HImode
, SOFT_SAVED_XY_REGNUM
),
1746 stack_pop_word
, scratch
);
1747 emit_move_after_reload (gen_rtx_REG (HImode
, SOFT_Z_REGNUM
),
1748 stack_pop_word
, scratch
);
1749 emit_move_after_reload (m68hc11_soft_tmp_reg
, stack_pop_word
, scratch
);
1752 /* Restore previous frame pointer. */
1753 if (frame_pointer_needed
)
1754 emit_move_after_reload (hard_frame_pointer_rtx
, stack_pop_word
, scratch
);
1756 /* If the trap handler returns some value, copy the value
1757 in D, X onto the stack so that the rti will pop the return value
1759 else if (current_function_trap
&& return_size
!= 0)
1761 rtx addr_reg
= stack_pointer_rtx
;
1765 emit_move_after_reload (scratch
, stack_pointer_rtx
, 0);
1768 emit_move_after_reload (gen_rtx_MEM (HImode
,
1769 gen_rtx_PLUS (HImode
, addr_reg
,
1770 const1_rtx
)), d_reg
, 0);
1771 if (return_size
> HARD_REG_SIZE
)
1772 emit_move_after_reload (gen_rtx_MEM (HImode
,
1773 gen_rtx_PLUS (HImode
, addr_reg
,
1774 GEN_INT (3))), ix_reg
, 0);
1777 emit_jump_insn (gen_return ());
1781 /* Low and High part extraction for 68HC11. These routines are
1782 similar to gen_lowpart and gen_highpart but they have been
1783 fixed to work for constants and 68HC11 specific registers. */
1786 m68hc11_gen_lowpart (enum machine_mode mode
, rtx x
)
1788 /* We assume that the low part of an auto-inc mode is the same with
1789 the mode changed and that the caller split the larger mode in the
1791 if (GET_CODE (x
) == MEM
&& m68hc11_auto_inc_p (XEXP (x
, 0)))
1793 return gen_rtx_MEM (mode
, XEXP (x
, 0));
1796 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
1797 floating-point constant. A CONST_DOUBLE is used whenever the
1798 constant requires more than one word in order to be adequately
1800 if (GET_CODE (x
) == CONST_DOUBLE
)
1804 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1808 if (GET_MODE (x
) == SFmode
)
1810 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
1811 REAL_VALUE_TO_TARGET_SINGLE (r
, l
[0]);
1817 split_double (x
, &first
, &second
);
1821 return GEN_INT (l
[0]);
1823 return gen_int_mode (l
[0], HImode
);
1827 l
[0] = CONST_DOUBLE_LOW (x
);
1832 return GEN_INT (l
[0]);
1834 gcc_assert (GET_MODE (x
) == SFmode
);
1835 return gen_int_mode (l
[0], HImode
);
1841 if (mode
== QImode
&& D_REG_P (x
))
1842 return gen_rtx_REG (mode
, HARD_B_REGNUM
);
1844 /* gen_lowpart crashes when it is called with a SUBREG. */
1845 if (GET_CODE (x
) == SUBREG
&& SUBREG_BYTE (x
) != 0)
1850 return gen_rtx_SUBREG (mode
, SUBREG_REG (x
), SUBREG_BYTE (x
) + 4);
1852 return gen_rtx_SUBREG (mode
, SUBREG_REG (x
), SUBREG_BYTE (x
) + 2);
1857 x
= gen_lowpart (mode
, x
);
1859 /* Return a different rtx to avoid to share it in several insns
1860 (when used by a split pattern). Sharing addresses within
1861 a MEM breaks the Z register replacement (and reloading). */
1862 if (GET_CODE (x
) == MEM
)
1868 m68hc11_gen_highpart (enum machine_mode mode
, rtx x
)
1870 /* We assume that the high part of an auto-inc mode is the same with
1871 the mode changed and that the caller split the larger mode in the
1873 if (GET_CODE (x
) == MEM
&& m68hc11_auto_inc_p (XEXP (x
, 0)))
1875 return gen_rtx_MEM (mode
, XEXP (x
, 0));
1878 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
1879 floating-point constant. A CONST_DOUBLE is used whenever the
1880 constant requires more than one word in order to be adequately
1882 if (GET_CODE (x
) == CONST_DOUBLE
)
1886 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1890 if (GET_MODE (x
) == SFmode
)
1892 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
1893 REAL_VALUE_TO_TARGET_SINGLE (r
, l
[1]);
1899 split_double (x
, &first
, &second
);
1903 return GEN_INT (l
[1]);
1905 return gen_int_mode ((l
[1] >> 16), HImode
);
1909 l
[1] = CONST_DOUBLE_HIGH (x
);
1915 return GEN_INT (l
[1]);
1917 gcc_assert (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
);
1918 return gen_int_mode ((l
[0] >> 16), HImode
);
1923 if (GET_CODE (x
) == CONST_INT
)
1925 HOST_WIDE_INT val
= INTVAL (x
);
1929 return gen_int_mode (val
>> 8, QImode
);
1931 else if (mode
== HImode
)
1933 return gen_int_mode (val
>> 16, HImode
);
1935 else if (mode
== SImode
)
1937 return gen_int_mode (val
>> 32, SImode
);
1940 if (mode
== QImode
&& D_REG_P (x
))
1941 return gen_rtx_REG (mode
, HARD_A_REGNUM
);
1943 /* There is no way in GCC to represent the upper part of a word register.
1944 To obtain the 8-bit upper part of a soft register, we change the
1945 reg into a mem rtx. This is possible because they are physically
1946 located in memory. There is no offset because we are big-endian. */
1947 if (mode
== QImode
&& S_REG_P (x
))
1951 /* Avoid the '*' for direct addressing mode when this
1952 addressing mode is disabled. */
1953 pos
= TARGET_NO_DIRECT_MODE
? 1 : 0;
1954 return gen_rtx_MEM (QImode
,
1955 gen_rtx_SYMBOL_REF (Pmode
,
1956 ®_names
[REGNO (x
)][pos
]));
1959 /* gen_highpart crashes when it is called with a SUBREG. */
1960 switch (GET_CODE (x
))
1963 return gen_rtx_SUBREG (mode
, XEXP (x
, 0), XEXP (x
, 1));
1965 if (REGNO (x
) < FIRST_PSEUDO_REGISTER
)
1966 return gen_rtx_REG (mode
, REGNO (x
));
1968 return gen_rtx_SUBREG (mode
, x
, 0);
1970 x
= change_address (x
, mode
, 0);
1972 /* Return a different rtx to avoid to share it in several insns
1973 (when used by a split pattern). Sharing addresses within
1974 a MEM breaks the Z register replacement (and reloading). */
1975 if (GET_CODE (x
) == MEM
)
1985 /* Obscure register manipulation. */
1987 /* Finds backward in the instructions to see if register 'reg' is
1988 dead. This is used when generating code to see if we can use 'reg'
1989 as a scratch register. This allows us to choose a better generation
1990 of code when we know that some register dies or can be clobbered. */
1993 dead_register_here (rtx x
, rtx reg
)
1999 x_reg
= gen_rtx_REG (SImode
, HARD_X_REGNUM
);
2003 for (p
= PREV_INSN (x
); p
&& GET_CODE (p
) != CODE_LABEL
; p
= PREV_INSN (p
))
2010 if (GET_CODE (body
) == CALL_INSN
)
2012 if (GET_CODE (body
) == JUMP_INSN
)
2015 if (GET_CODE (body
) == SET
)
2017 rtx dst
= XEXP (body
, 0);
2019 if (GET_CODE (dst
) == REG
&& REGNO (dst
) == REGNO (reg
))
2021 if (x_reg
&& rtx_equal_p (dst
, x_reg
))
2024 if (find_regno_note (p
, REG_DEAD
, REGNO (reg
)))
2027 else if (reg_mentioned_p (reg
, p
)
2028 || (x_reg
&& reg_mentioned_p (x_reg
, p
)))
2032 /* Scan forward to see if the register is set in some insns and never
2034 for (p
= x
/*NEXT_INSN (x) */ ; p
; p
= NEXT_INSN (p
))
2038 if (GET_CODE (p
) == CODE_LABEL
2039 || GET_CODE (p
) == JUMP_INSN
2040 || GET_CODE (p
) == CALL_INSN
|| GET_CODE (p
) == BARRIER
)
2043 if (GET_CODE (p
) != INSN
)
2047 if (GET_CODE (body
) == SET
)
2049 rtx src
= XEXP (body
, 1);
2050 rtx dst
= XEXP (body
, 0);
2052 if (GET_CODE (dst
) == REG
2053 && REGNO (dst
) == REGNO (reg
) && !reg_mentioned_p (reg
, src
))
2057 /* Register is used (may be in source or in dest). */
2058 if (reg_mentioned_p (reg
, p
)
2059 || (x_reg
!= 0 && GET_MODE (p
) == SImode
2060 && reg_mentioned_p (x_reg
, p
)))
2063 return p
== 0 ? 1 : 0;
2067 /* Code generation operations called from machine description file. */
2069 /* Print the name of register 'regno' in the assembly file. */
2071 asm_print_register (FILE *file
, int regno
)
2073 const char *name
= reg_names
[regno
];
2075 if (TARGET_NO_DIRECT_MODE
&& name
[0] == '*')
2078 fprintf (file
, "%s", name
);
2081 /* A C compound statement to output to stdio stream STREAM the
2082 assembler syntax for an instruction operand X. X is an RTL
2085 CODE is a value that can be used to specify one of several ways
2086 of printing the operand. It is used when identical operands
2087 must be printed differently depending on the context. CODE
2088 comes from the `%' specification that was used to request
2089 printing of the operand. If the specification was just `%DIGIT'
2090 then CODE is 0; if the specification was `%LTR DIGIT' then CODE
2091 is the ASCII code for LTR.
2093 If X is a register, this macro should print the register's name.
2094 The names can be found in an array `reg_names' whose type is
2095 `char *[]'. `reg_names' is initialized from `REGISTER_NAMES'.
2097 When the machine description has a specification `%PUNCT' (a `%'
2098 followed by a punctuation character), this macro is called with
2099 a null pointer for X and the punctuation character for CODE.
2101 The M68HC11 specific codes are:
2103 'b' for the low part of the operand.
2104 'h' for the high part of the operand
2105 The 'b' or 'h' modifiers have no effect if the operand has
2106 the QImode and is not a S_REG_P (soft register). If the
2107 operand is a hard register, these two modifiers have no effect.
2108 't' generate the temporary scratch register. The operand is
2110 'T' generate the low-part temporary scratch register. The operand is
2114 print_operand (FILE *file
, rtx op
, int letter
)
2118 asm_print_register (file
, SOFT_TMP_REGNUM
);
2121 else if (letter
== 'T')
2123 asm_print_register (file
, SOFT_TMP_REGNUM
);
2124 fprintf (file
, "+1");
2127 else if (letter
== '#')
2129 asm_fprintf (file
, "%I");
2132 if (GET_CODE (op
) == REG
)
2134 if (letter
== 'b' && S_REG_P (op
))
2136 asm_print_register (file
, REGNO (op
));
2137 fprintf (file
, "+1");
2139 else if (letter
== 'b' && D_REG_P (op
))
2141 asm_print_register (file
, HARD_B_REGNUM
);
2145 asm_print_register (file
, REGNO (op
));
2150 if (GET_CODE (op
) == SYMBOL_REF
&& (letter
== 'b' || letter
== 'h'))
2153 asm_fprintf (file
, "%I%%lo(");
2155 asm_fprintf (file
, "%I%%hi(");
2157 output_addr_const (file
, op
);
2158 fprintf (file
, ")");
2162 /* Get the low or high part of the operand when 'b' or 'h' modifiers
2163 are specified. If we already have a QImode, there is nothing to do. */
2164 if (GET_MODE (op
) == HImode
|| GET_MODE (op
) == VOIDmode
)
2168 op
= m68hc11_gen_lowpart (QImode
, op
);
2170 else if (letter
== 'h')
2172 op
= m68hc11_gen_highpart (QImode
, op
);
2176 if (GET_CODE (op
) == MEM
)
2178 rtx base
= XEXP (op
, 0);
2179 switch (GET_CODE (base
))
2182 gcc_assert (TARGET_M6812
);
2183 fprintf (file
, "%u,-", GET_MODE_SIZE (GET_MODE (op
)));
2184 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2188 gcc_assert (TARGET_M6812
);
2189 fprintf (file
, "%u,", GET_MODE_SIZE (GET_MODE (op
)));
2190 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2191 fprintf (file
, "-");
2195 gcc_assert (TARGET_M6812
);
2196 fprintf (file
, "%u,", GET_MODE_SIZE (GET_MODE (op
)));
2197 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2198 fprintf (file
, "+");
2202 gcc_assert (TARGET_M6812
);
2203 fprintf (file
, "%u,+", GET_MODE_SIZE (GET_MODE (op
)));
2204 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2208 gcc_assert (TARGET_M6812
);
2209 fprintf (file
, "[");
2210 print_operand_address (file
, XEXP (base
, 0));
2211 fprintf (file
, "]");
2215 if (m68hc11_page0_symbol_p (base
))
2216 fprintf (file
, "*");
2218 output_address (base
);
2222 else if (GET_CODE (op
) == CONST_DOUBLE
&& GET_MODE (op
) == SFmode
)
2227 REAL_VALUE_FROM_CONST_DOUBLE (r
, op
);
2228 REAL_VALUE_TO_TARGET_SINGLE (r
, l
);
2229 asm_fprintf (file
, "%I0x%lx", l
);
2231 else if (GET_CODE (op
) == CONST_DOUBLE
&& GET_MODE (op
) == DFmode
)
2235 real_to_decimal (dstr
, CONST_DOUBLE_REAL_VALUE (op
),
2236 sizeof (dstr
), 0, 1);
2237 asm_fprintf (file
, "%I0r%s", dstr
);
2241 int need_parenthesize
= 0;
2244 asm_fprintf (file
, "%I");
2246 need_parenthesize
= must_parenthesize (op
);
2248 if (need_parenthesize
)
2249 fprintf (file
, "(");
2251 output_addr_const (file
, op
);
2252 if (need_parenthesize
)
2253 fprintf (file
, ")");
2257 /* Returns true if the operand 'op' must be printed with parenthesis
2258 around it. This must be done only if there is a symbol whose name
2259 is a processor register. */
2261 must_parenthesize (rtx op
)
2265 switch (GET_CODE (op
))
2268 name
= XSTR (op
, 0);
2269 /* Avoid a conflict between symbol name and a possible
2271 return (strcasecmp (name
, "a") == 0
2272 || strcasecmp (name
, "b") == 0
2273 || strcasecmp (name
, "d") == 0
2274 || strcasecmp (name
, "x") == 0
2275 || strcasecmp (name
, "y") == 0
2276 || strcasecmp (name
, "ix") == 0
2277 || strcasecmp (name
, "iy") == 0
2278 || strcasecmp (name
, "pc") == 0
2279 || strcasecmp (name
, "sp") == 0
2280 || strcasecmp (name
, "ccr") == 0) ? 1 : 0;
2284 return must_parenthesize (XEXP (op
, 0))
2285 || must_parenthesize (XEXP (op
, 1));
2291 return must_parenthesize (XEXP (op
, 0));
2302 /* A C compound statement to output to stdio stream STREAM the
2303 assembler syntax for an instruction operand that is a memory
2304 reference whose address is ADDR. ADDR is an RTL expression. */
2307 print_operand_address (FILE *file
, rtx addr
)
2311 int need_parenthesis
= 0;
2313 switch (GET_CODE (addr
))
2316 gcc_assert (REG_P (addr
) && REG_OK_FOR_BASE_STRICT_P (addr
));
2318 fprintf (file
, "0,");
2319 asm_print_register (file
, REGNO (addr
));
2323 base
= XEXP (addr
, 0);
2324 switch (GET_CODE (base
))
2327 gcc_assert (TARGET_M6812
);
2328 fprintf (file
, "%u,-", GET_MODE_SIZE (GET_MODE (addr
)));
2329 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2333 gcc_assert (TARGET_M6812
);
2334 fprintf (file
, "%u,", GET_MODE_SIZE (GET_MODE (addr
)));
2335 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2336 fprintf (file
, "-");
2340 gcc_assert (TARGET_M6812
);
2341 fprintf (file
, "%u,", GET_MODE_SIZE (GET_MODE (addr
)));
2342 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2343 fprintf (file
, "+");
2347 gcc_assert (TARGET_M6812
);
2348 fprintf (file
, "%u,+", GET_MODE_SIZE (GET_MODE (addr
)));
2349 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2353 need_parenthesis
= must_parenthesize (base
);
2354 if (need_parenthesis
)
2355 fprintf (file
, "(");
2357 output_addr_const (file
, base
);
2358 if (need_parenthesis
)
2359 fprintf (file
, ")");
2365 base
= XEXP (addr
, 0);
2366 offset
= XEXP (addr
, 1);
2367 if (!G_REG_P (base
) && G_REG_P (offset
))
2369 base
= XEXP (addr
, 1);
2370 offset
= XEXP (addr
, 0);
2372 if (CONSTANT_ADDRESS_P (base
))
2374 need_parenthesis
= must_parenthesize (addr
);
2376 gcc_assert (CONSTANT_ADDRESS_P (offset
));
2377 if (need_parenthesis
)
2378 fprintf (file
, "(");
2380 output_addr_const (file
, base
);
2381 fprintf (file
, "+");
2382 output_addr_const (file
, offset
);
2383 if (need_parenthesis
)
2384 fprintf (file
, ")");
2388 gcc_assert (REG_P (base
) && REG_OK_FOR_BASE_STRICT_P (base
));
2391 gcc_assert (TARGET_M6812
);
2392 asm_print_register (file
, REGNO (offset
));
2393 fprintf (file
, ",");
2394 asm_print_register (file
, REGNO (base
));
2398 need_parenthesis
= must_parenthesize (offset
);
2399 if (need_parenthesis
)
2400 fprintf (file
, "(");
2402 output_addr_const (file
, offset
);
2403 if (need_parenthesis
)
2404 fprintf (file
, ")");
2405 fprintf (file
, ",");
2406 asm_print_register (file
, REGNO (base
));
2412 if (GET_CODE (addr
) == CONST_INT
2413 && INTVAL (addr
) < 0x8000 && INTVAL (addr
) >= -0x8000)
2415 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (addr
));
2419 need_parenthesis
= must_parenthesize (addr
);
2420 if (need_parenthesis
)
2421 fprintf (file
, "(");
2423 output_addr_const (file
, addr
);
2424 if (need_parenthesis
)
2425 fprintf (file
, ")");
2432 /* Splitting of some instructions. */
2435 m68hc11_expand_compare (enum rtx_code code
, rtx op0
, rtx op1
)
2439 gcc_assert (GET_MODE_CLASS (GET_MODE (op0
)) != MODE_FLOAT
);
2440 emit_insn (gen_rtx_SET (VOIDmode
, cc0_rtx
,
2441 gen_rtx_COMPARE (VOIDmode
, op0
, op1
)));
2442 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, cc0_rtx
, const0_rtx
);
2448 m68hc11_expand_compare_and_branch (enum rtx_code code
, rtx op0
, rtx op1
,
2453 switch (GET_MODE (op0
))
2457 tmp
= m68hc11_expand_compare (code
, op0
, op1
);
2458 tmp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, tmp
,
2459 gen_rtx_LABEL_REF (VOIDmode
, label
),
2461 emit_jump_insn (gen_rtx_SET (VOIDmode
, pc_rtx
, tmp
));
2465 /* SCz: from i386.c */
2468 /* Don't expand the comparison early, so that we get better code
2469 when jump or whoever decides to reverse the comparison. */
2474 code
= m68hc11_prepare_fp_compare_args (code
, &m68hc11_compare_op0
,
2475 &m68hc11_compare_op1
);
2477 tmp
= gen_rtx_fmt_ee (code
, m68hc11_fp_compare_mode (code
),
2478 m68hc11_compare_op0
, m68hc11_compare_op1
);
2479 tmp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, tmp
,
2480 gen_rtx_LABEL_REF (VOIDmode
, label
),
2482 tmp
= gen_rtx_SET (VOIDmode
, pc_rtx
, tmp
);
2484 use_fcomi
= ix86_use_fcomi_compare (code
);
2485 vec
= rtvec_alloc (3 + !use_fcomi
);
2486 RTVEC_ELT (vec
, 0) = tmp
;
2488 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCFPmode
, 18));
2490 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCFPmode
, 17));
2493 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_SCRATCH (HImode
));
2495 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, vec
));
2501 /* Expand SImode branch into multiple compare+branch. */
2503 rtx lo
[2], hi
[2], label2
;
2504 enum rtx_code code1
, code2
, code3
;
2506 if (CONSTANT_P (op0
) && !CONSTANT_P (op1
))
2511 code
= swap_condition (code
);
2513 lo
[0] = m68hc11_gen_lowpart (HImode
, op0
);
2514 lo
[1] = m68hc11_gen_lowpart (HImode
, op1
);
2515 hi
[0] = m68hc11_gen_highpart (HImode
, op0
);
2516 hi
[1] = m68hc11_gen_highpart (HImode
, op1
);
2518 /* Otherwise, if we are doing less-than, op1 is a constant and the
2519 low word is zero, then we can just examine the high word. */
2521 if (GET_CODE (hi
[1]) == CONST_INT
&& lo
[1] == const0_rtx
2522 && (code
== LT
|| code
== LTU
))
2524 return m68hc11_expand_compare_and_branch (code
, hi
[0], hi
[1],
2528 /* Otherwise, we need two or three jumps. */
2530 label2
= gen_label_rtx ();
2533 code2
= swap_condition (code
);
2534 code3
= unsigned_condition (code
);
2575 * if (hi(a) < hi(b)) goto true;
2576 * if (hi(a) > hi(b)) goto false;
2577 * if (lo(a) < lo(b)) goto true;
2580 if (code1
!= UNKNOWN
)
2581 m68hc11_expand_compare_and_branch (code1
, hi
[0], hi
[1], label
);
2582 if (code2
!= UNKNOWN
)
2583 m68hc11_expand_compare_and_branch (code2
, hi
[0], hi
[1], label2
);
2585 m68hc11_expand_compare_and_branch (code3
, lo
[0], lo
[1], label
);
2587 if (code2
!= UNKNOWN
)
2588 emit_label (label2
);
2598 /* Return the increment/decrement mode of a MEM if it is such.
2599 Return CONST if it is anything else. */
2601 autoinc_mode (rtx x
)
2603 if (GET_CODE (x
) != MEM
)
2607 if (GET_CODE (x
) == PRE_INC
2608 || GET_CODE (x
) == PRE_DEC
2609 || GET_CODE (x
) == POST_INC
2610 || GET_CODE (x
) == POST_DEC
)
2611 return GET_CODE (x
);
2617 m68hc11_make_autoinc_notes (rtx
*x
, void *data
)
2621 switch (GET_CODE (*x
))
2628 REG_NOTES (insn
) = alloc_EXPR_LIST (REG_INC
, XEXP (*x
, 0),
2637 /* Split a DI, SI or HI move into several smaller move operations.
2638 The scratch register 'scratch' is used as a temporary to load
2639 store intermediate values. It must be a hard register. */
2641 m68hc11_split_move (rtx to
, rtx from
, rtx scratch
)
2643 rtx low_to
, low_from
;
2644 rtx high_to
, high_from
;
2646 enum machine_mode mode
;
2648 int autoinc_from
= autoinc_mode (from
);
2649 int autoinc_to
= autoinc_mode (to
);
2651 mode
= GET_MODE (to
);
2653 /* If the TO and FROM contain autoinc modes that are not compatible
2654 together (one pop and the other a push), we must change one to
2655 an offsetable operand and generate an appropriate add at the end. */
2656 if (TARGET_M6812
&& GET_MODE_SIZE (mode
) > 2)
2661 /* The source uses an autoinc mode which is not compatible with
2662 a split (this would result in a word swap). */
2663 if (autoinc_from
== PRE_INC
|| autoinc_from
== POST_DEC
)
2665 code
= GET_CODE (XEXP (from
, 0));
2666 reg
= XEXP (XEXP (from
, 0), 0);
2667 offset
= GET_MODE_SIZE (GET_MODE (from
));
2668 if (code
== POST_DEC
)
2671 if (code
== PRE_INC
)
2672 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2674 m68hc11_split_move (to
, gen_rtx_MEM (GET_MODE (from
), reg
), scratch
);
2675 if (code
== POST_DEC
)
2676 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2680 /* Likewise for destination. */
2681 if (autoinc_to
== PRE_INC
|| autoinc_to
== POST_DEC
)
2683 code
= GET_CODE (XEXP (to
, 0));
2684 reg
= XEXP (XEXP (to
, 0), 0);
2685 offset
= GET_MODE_SIZE (GET_MODE (to
));
2686 if (code
== POST_DEC
)
2689 if (code
== PRE_INC
)
2690 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2692 m68hc11_split_move (gen_rtx_MEM (GET_MODE (to
), reg
), from
, scratch
);
2693 if (code
== POST_DEC
)
2694 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2698 /* The source and destination auto increment modes must be compatible
2699 with each other: same direction. */
2700 if ((autoinc_to
!= autoinc_from
2701 && autoinc_to
!= CONST
&& autoinc_from
!= CONST
)
2702 /* The destination address register must not be used within
2703 the source operand because the source address would change
2704 while doing the copy. */
2705 || (autoinc_to
!= CONST
2706 && reg_mentioned_p (XEXP (XEXP (to
, 0), 0), from
)
2707 && !IS_STACK_PUSH (to
)))
2709 /* Must change the destination. */
2710 code
= GET_CODE (XEXP (to
, 0));
2711 reg
= XEXP (XEXP (to
, 0), 0);
2712 offset
= GET_MODE_SIZE (GET_MODE (to
));
2713 if (code
== PRE_DEC
|| code
== POST_DEC
)
2716 if (code
== PRE_DEC
|| code
== PRE_INC
)
2717 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2718 m68hc11_split_move (gen_rtx_MEM (GET_MODE (to
), reg
), from
, scratch
);
2719 if (code
== POST_DEC
|| code
== POST_INC
)
2720 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2725 /* Likewise, the source address register must not be used within
2726 the destination operand. */
2727 if (autoinc_from
!= CONST
2728 && reg_mentioned_p (XEXP (XEXP (from
, 0), 0), to
)
2729 && !IS_STACK_PUSH (to
))
2731 /* Must change the source. */
2732 code
= GET_CODE (XEXP (from
, 0));
2733 reg
= XEXP (XEXP (from
, 0), 0);
2734 offset
= GET_MODE_SIZE (GET_MODE (from
));
2735 if (code
== PRE_DEC
|| code
== POST_DEC
)
2738 if (code
== PRE_DEC
|| code
== PRE_INC
)
2739 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2740 m68hc11_split_move (to
, gen_rtx_MEM (GET_MODE (from
), reg
), scratch
);
2741 if (code
== POST_DEC
|| code
== POST_INC
)
2742 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2748 if (GET_MODE_SIZE (mode
) == 8)
2750 else if (GET_MODE_SIZE (mode
) == 4)
2756 && IS_STACK_PUSH (to
)
2757 && reg_mentioned_p (gen_rtx_REG (HImode
, HARD_SP_REGNUM
), from
))
2763 else if (mode
== HImode
)
2771 low_to
= m68hc11_gen_lowpart (mode
, to
);
2772 high_to
= m68hc11_gen_highpart (mode
, to
);
2774 low_from
= m68hc11_gen_lowpart (mode
, from
);
2775 high_from
= m68hc11_gen_highpart (mode
, from
);
2779 high_from
= adjust_address (high_from
, mode
, offset
);
2780 low_from
= high_from
;
2783 /* When copying with a POST_INC mode, we must copy the
2784 high part and then the low part to guarantee a correct
2787 && GET_MODE_SIZE (mode
) >= 2
2788 && autoinc_from
!= autoinc_to
2789 && (autoinc_from
== POST_INC
|| autoinc_to
== POST_INC
))
2798 low_from
= high_from
;
2803 m68hc11_split_move (low_to
, low_from
, scratch
);
2804 m68hc11_split_move (high_to
, high_from
, scratch
);
2806 else if (H_REG_P (to
) || H_REG_P (from
)
2807 || (low_from
== const0_rtx
2808 && high_from
== const0_rtx
2809 && ! push_operand (to
, GET_MODE (to
))
2810 && ! H_REG_P (scratch
))
2812 && (!m68hc11_register_indirect_p (from
, GET_MODE (from
))
2813 || m68hc11_small_indexed_indirect_p (from
,
2815 && (!m68hc11_register_indirect_p (to
, GET_MODE (to
))
2816 || m68hc11_small_indexed_indirect_p (to
, GET_MODE (to
)))))
2818 insn
= emit_move_insn (low_to
, low_from
);
2819 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
2821 insn
= emit_move_insn (high_to
, high_from
);
2822 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
2826 insn
= emit_move_insn (scratch
, low_from
);
2827 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
2828 insn
= emit_move_insn (low_to
, scratch
);
2829 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
2831 insn
= emit_move_insn (scratch
, high_from
);
2832 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
2833 insn
= emit_move_insn (high_to
, scratch
);
2834 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
2839 simplify_logical (enum machine_mode mode
, int code
, rtx operand
, rtx
*result
)
2845 if (GET_CODE (operand
) != CONST_INT
)
2853 val
= INTVAL (operand
);
2857 if ((val
& mask
) == 0)
2859 if ((val
& mask
) == mask
)
2860 *result
= constm1_rtx
;
2864 if ((val
& mask
) == 0)
2865 *result
= const0_rtx
;
2866 if ((val
& mask
) == mask
)
2871 if ((val
& mask
) == 0)
2879 m68hc11_emit_logical (enum machine_mode mode
, int code
, rtx
*operands
)
2884 need_copy
= (rtx_equal_p (operands
[0], operands
[1])
2885 || rtx_equal_p (operands
[0], operands
[2])) ? 0 : 1;
2887 operands
[1] = simplify_logical (mode
, code
, operands
[1], &result
);
2888 operands
[2] = simplify_logical (mode
, code
, operands
[2], &result
);
2890 if (result
&& GET_CODE (result
) == CONST_INT
)
2892 if (!H_REG_P (operands
[0]) && operands
[3]
2893 && (INTVAL (result
) != 0 || IS_STACK_PUSH (operands
[0])))
2895 emit_move_insn (operands
[3], result
);
2896 emit_move_insn (operands
[0], operands
[3]);
2900 emit_move_insn (operands
[0], result
);
2903 else if (operands
[1] != 0 && operands
[2] != 0)
2907 if (!H_REG_P (operands
[0]) && operands
[3])
2909 emit_move_insn (operands
[3], operands
[1]);
2910 emit_insn (gen_rtx_SET (mode
,
2912 gen_rtx_fmt_ee (code
, mode
,
2913 operands
[3], operands
[2])));
2914 insn
= emit_move_insn (operands
[0], operands
[3]);
2918 insn
= emit_insn (gen_rtx_SET (mode
,
2920 gen_rtx_fmt_ee (code
, mode
,
2926 /* The logical operation is similar to a copy. */
2931 if (GET_CODE (operands
[1]) == CONST_INT
)
2936 if (!H_REG_P (operands
[0]) && !H_REG_P (src
))
2938 emit_move_insn (operands
[3], src
);
2939 emit_move_insn (operands
[0], operands
[3]);
2943 emit_move_insn (operands
[0], src
);
2949 m68hc11_split_logical (enum machine_mode mode
, int code
, rtx
*operands
)
2954 low
[0] = m68hc11_gen_lowpart (mode
, operands
[0]);
2955 low
[1] = m68hc11_gen_lowpart (mode
, operands
[1]);
2956 low
[2] = m68hc11_gen_lowpart (mode
, operands
[2]);
2958 high
[0] = m68hc11_gen_highpart (mode
, operands
[0]);
2959 high
[1] = m68hc11_gen_highpart (mode
, operands
[1]);
2960 high
[2] = m68hc11_gen_highpart (mode
, operands
[2]);
2962 low
[3] = operands
[3];
2963 high
[3] = operands
[3];
2966 m68hc11_split_logical (HImode
, code
, low
);
2967 m68hc11_split_logical (HImode
, code
, high
);
2971 m68hc11_emit_logical (mode
, code
, low
);
2972 m68hc11_emit_logical (mode
, code
, high
);
2976 /* Code generation. */
2979 m68hc11_output_swap (rtx insn ATTRIBUTE_UNUSED
, rtx operands
[])
2981 /* We have to be careful with the cc_status. An address register swap
2982 is generated for some comparison. The comparison is made with D
2983 but the branch really uses the address register. See the split
2984 pattern for compare. The xgdx/xgdy preserve the flags but after
2985 the exchange, the flags will reflect to the value of X and not D.
2986 Tell this by setting the cc_status according to the cc_prev_status. */
2987 if (X_REG_P (operands
[1]) || X_REG_P (operands
[0]))
2989 if (cc_prev_status
.value1
!= 0
2990 && (D_REG_P (cc_prev_status
.value1
)
2991 || X_REG_P (cc_prev_status
.value1
)))
2993 cc_status
= cc_prev_status
;
2994 if (D_REG_P (cc_status
.value1
))
2995 cc_status
.value1
= gen_rtx_REG (GET_MODE (cc_status
.value1
),
2998 cc_status
.value1
= gen_rtx_REG (GET_MODE (cc_status
.value1
),
3004 output_asm_insn ("xgdx", operands
);
3008 if (cc_prev_status
.value1
!= 0
3009 && (D_REG_P (cc_prev_status
.value1
)
3010 || Y_REG_P (cc_prev_status
.value1
)))
3012 cc_status
= cc_prev_status
;
3013 if (D_REG_P (cc_status
.value1
))
3014 cc_status
.value1
= gen_rtx_REG (GET_MODE (cc_status
.value1
),
3017 cc_status
.value1
= gen_rtx_REG (GET_MODE (cc_status
.value1
),
3023 output_asm_insn ("xgdy", operands
);
3027 /* Returns 1 if the next insn after 'insn' is a test of the register 'reg'.
3028 This is used to decide whether a move that set flags should be used
3031 next_insn_test_reg (rtx insn
, rtx reg
)
3035 insn
= next_nonnote_insn (insn
);
3036 if (GET_CODE (insn
) != INSN
)
3039 body
= PATTERN (insn
);
3040 if (sets_cc0_p (body
) != 1)
3043 if (rtx_equal_p (XEXP (body
, 1), reg
) == 0)
3049 /* Generate the code to move a 16-bit operand into another one. */
3052 m68hc11_gen_movhi (rtx insn
, rtx
*operands
)
3056 /* Move a register or memory to the same location.
3057 This is possible because such insn can appear
3058 in a non-optimizing mode. */
3059 if (operands
[0] == operands
[1] || rtx_equal_p (operands
[0], operands
[1]))
3061 cc_status
= cc_prev_status
;
3067 rtx from
= operands
[1];
3068 rtx to
= operands
[0];
3070 if (IS_STACK_PUSH (to
) && H_REG_P (from
))
3072 cc_status
= cc_prev_status
;
3073 switch (REGNO (from
))
3078 output_asm_insn ("psh%1", operands
);
3080 case HARD_SP_REGNUM
:
3081 output_asm_insn ("sts\t2,-sp", operands
);
3088 if (IS_STACK_POP (from
) && H_REG_P (to
))
3090 cc_status
= cc_prev_status
;
3096 output_asm_insn ("pul%0", operands
);
3103 if (H_REG_P (operands
[0]) && H_REG_P (operands
[1]))
3105 m68hc11_notice_keep_cc (operands
[0]);
3106 output_asm_insn ("tfr\t%1,%0", operands
);
3108 else if (H_REG_P (operands
[0]))
3110 if (SP_REG_P (operands
[0]))
3111 output_asm_insn ("lds\t%1", operands
);
3113 output_asm_insn ("ld%0\t%1", operands
);
3115 else if (H_REG_P (operands
[1]))
3117 if (SP_REG_P (operands
[1]))
3118 output_asm_insn ("sts\t%0", operands
);
3120 output_asm_insn ("st%1\t%0", operands
);
3123 /* The 68hc12 does not support (MEM:HI (MEM:HI)) with the movw
3124 instruction. We have to use a scratch register as temporary location.
3125 Trying to use a specific pattern or constrain failed. */
3126 else if (GET_CODE (to
) == MEM
&& GET_CODE (XEXP (to
, 0)) == MEM
)
3133 if (dead_register_here (insn
, d_reg
))
3135 else if (dead_register_here (insn
, ix_reg
))
3137 else if (dead_register_here (insn
, iy_reg
))
3143 output_asm_insn ("psh%3", ops
);
3148 output_asm_insn ("ld%1\t%2", ops
);
3149 output_asm_insn ("st%1\t%0", ops
);
3151 output_asm_insn ("pul%3", ops
);
3154 /* Use movw for non-null constants or when we are clearing
3155 a volatile memory reference. However, this is possible
3156 only if the memory reference has a small offset or is an
3157 absolute address. */
3158 else if (GET_CODE (from
) == CONST_INT
3159 && INTVAL (from
) == 0
3160 && (MEM_VOLATILE_P (to
) == 0
3161 || m68hc11_small_indexed_indirect_p (to
, HImode
) == 0))
3163 output_asm_insn ("clr\t%h0", operands
);
3164 output_asm_insn ("clr\t%b0", operands
);
3168 if ((m68hc11_register_indirect_p (from
, GET_MODE (from
))
3169 && !m68hc11_small_indexed_indirect_p (from
, GET_MODE (from
)))
3170 || (m68hc11_register_indirect_p (to
, GET_MODE (to
))
3171 && !m68hc11_small_indexed_indirect_p (to
, GET_MODE (to
))))
3177 ops
[0] = operands
[2];
3180 m68hc11_gen_movhi (insn
, ops
);
3182 ops
[1] = operands
[2];
3183 m68hc11_gen_movhi (insn
, ops
);
3188 /* !!!! SCz wrong here. */
3189 fatal_insn ("move insn not handled", insn
);
3194 m68hc11_notice_keep_cc (operands
[0]);
3195 output_asm_insn ("movw\t%1,%0", operands
);
3201 if (IS_STACK_POP (operands
[1]) && H_REG_P (operands
[0]))
3203 cc_status
= cc_prev_status
;
3204 switch (REGNO (operands
[0]))
3208 output_asm_insn ("pul%0", operands
);
3211 output_asm_insn ("pula", operands
);
3212 output_asm_insn ("pulb", operands
);
3219 /* Some moves to a hard register are special. Not all of them
3220 are really supported and we have to use a temporary
3221 location to provide them (either the stack of a temp var). */
3222 if (H_REG_P (operands
[0]))
3224 switch (REGNO (operands
[0]))
3227 if (X_REG_P (operands
[1]))
3229 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_X_REGNUM
))
3231 m68hc11_output_swap (insn
, operands
);
3233 else if (next_insn_test_reg (insn
, operands
[0]))
3235 output_asm_insn ("stx\t%t0\n\tldd\t%t0", operands
);
3239 m68hc11_notice_keep_cc (operands
[0]);
3240 output_asm_insn ("pshx\n\tpula\n\tpulb", operands
);
3243 else if (Y_REG_P (operands
[1]))
3245 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_Y_REGNUM
))
3247 m68hc11_output_swap (insn
, operands
);
3251 /* %t means *ZTMP scratch register. */
3252 output_asm_insn ("sty\t%t1", operands
);
3253 output_asm_insn ("ldd\t%t1", operands
);
3256 else if (SP_REG_P (operands
[1]))
3261 if (optimize
== 0 || dead_register_here (insn
, ix_reg
) == 0)
3262 output_asm_insn ("xgdx", operands
);
3263 output_asm_insn ("tsx", operands
);
3264 output_asm_insn ("xgdx", operands
);
3266 else if (IS_STACK_POP (operands
[1]))
3268 output_asm_insn ("pula\n\tpulb", operands
);
3270 else if (GET_CODE (operands
[1]) == CONST_INT
3271 && INTVAL (operands
[1]) == 0)
3273 output_asm_insn ("clra\n\tclrb", operands
);
3277 output_asm_insn ("ldd\t%1", operands
);
3282 if (D_REG_P (operands
[1]))
3284 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_D_REGNUM
))
3286 m68hc11_output_swap (insn
, operands
);
3288 else if (next_insn_test_reg (insn
, operands
[0]))
3290 output_asm_insn ("std\t%t0\n\tldx\t%t0", operands
);
3294 m68hc11_notice_keep_cc (operands
[0]);
3295 output_asm_insn ("pshb", operands
);
3296 output_asm_insn ("psha", operands
);
3297 output_asm_insn ("pulx", operands
);
3300 else if (Y_REG_P (operands
[1]))
3302 /* When both D and Y are dead, use the sequence xgdy, xgdx
3303 to move Y into X. The D and Y registers are modified. */
3304 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_Y_REGNUM
)
3305 && dead_register_here (insn
, d_reg
))
3307 output_asm_insn ("xgdy", operands
);
3308 output_asm_insn ("xgdx", operands
);
3311 else if (!optimize_size
)
3313 output_asm_insn ("sty\t%t1", operands
);
3314 output_asm_insn ("ldx\t%t1", operands
);
3319 output_asm_insn ("pshy", operands
);
3320 output_asm_insn ("pulx", operands
);
3323 else if (SP_REG_P (operands
[1]))
3325 /* tsx, tsy preserve the flags */
3326 cc_status
= cc_prev_status
;
3327 output_asm_insn ("tsx", operands
);
3331 output_asm_insn ("ldx\t%1", operands
);
3336 if (D_REG_P (operands
[1]))
3338 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_D_REGNUM
))
3340 m68hc11_output_swap (insn
, operands
);
3344 output_asm_insn ("std\t%t1", operands
);
3345 output_asm_insn ("ldy\t%t1", operands
);
3348 else if (X_REG_P (operands
[1]))
3350 /* When both D and X are dead, use the sequence xgdx, xgdy
3351 to move X into Y. The D and X registers are modified. */
3352 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_X_REGNUM
)
3353 && dead_register_here (insn
, d_reg
))
3355 output_asm_insn ("xgdx", operands
);
3356 output_asm_insn ("xgdy", operands
);
3359 else if (!optimize_size
)
3361 output_asm_insn ("stx\t%t1", operands
);
3362 output_asm_insn ("ldy\t%t1", operands
);
3367 output_asm_insn ("pshx", operands
);
3368 output_asm_insn ("puly", operands
);
3371 else if (SP_REG_P (operands
[1]))
3373 /* tsx, tsy preserve the flags */
3374 cc_status
= cc_prev_status
;
3375 output_asm_insn ("tsy", operands
);
3379 output_asm_insn ("ldy\t%1", operands
);
3383 case HARD_SP_REGNUM
:
3384 if (D_REG_P (operands
[1]))
3386 m68hc11_notice_keep_cc (operands
[0]);
3387 output_asm_insn ("xgdx", operands
);
3388 output_asm_insn ("txs", operands
);
3389 output_asm_insn ("xgdx", operands
);
3391 else if (X_REG_P (operands
[1]))
3393 /* tys, txs preserve the flags */
3394 cc_status
= cc_prev_status
;
3395 output_asm_insn ("txs", operands
);
3397 else if (Y_REG_P (operands
[1]))
3399 /* tys, txs preserve the flags */
3400 cc_status
= cc_prev_status
;
3401 output_asm_insn ("tys", operands
);
3405 /* lds sets the flags but the des does not. */
3407 output_asm_insn ("lds\t%1", operands
);
3408 output_asm_insn ("des", operands
);
3413 fatal_insn ("invalid register in the move instruction", insn
);
3418 if (SP_REG_P (operands
[1]) && REG_P (operands
[0])
3419 && REGNO (operands
[0]) == HARD_FRAME_POINTER_REGNUM
)
3421 output_asm_insn ("sts\t%0", operands
);
3425 if (IS_STACK_PUSH (operands
[0]) && H_REG_P (operands
[1]))
3427 cc_status
= cc_prev_status
;
3428 switch (REGNO (operands
[1]))
3432 output_asm_insn ("psh%1", operands
);
3435 output_asm_insn ("pshb", operands
);
3436 output_asm_insn ("psha", operands
);
3444 /* Operand 1 must be a hard register. */
3445 if (!H_REG_P (operands
[1]))
3447 fatal_insn ("invalid operand in the instruction", insn
);
3450 reg
= REGNO (operands
[1]);
3454 output_asm_insn ("std\t%0", operands
);
3458 output_asm_insn ("stx\t%0", operands
);
3462 output_asm_insn ("sty\t%0", operands
);
3465 case HARD_SP_REGNUM
:
3469 if (REG_P (operands
[0]) && REGNO (operands
[0]) == SOFT_TMP_REGNUM
)
3471 output_asm_insn ("pshx", operands
);
3472 output_asm_insn ("tsx", operands
);
3473 output_asm_insn ("inx", operands
);
3474 output_asm_insn ("inx", operands
);
3475 output_asm_insn ("stx\t%0", operands
);
3476 output_asm_insn ("pulx", operands
);
3479 else if (reg_mentioned_p (ix_reg
, operands
[0]))
3481 output_asm_insn ("sty\t%t0", operands
);
3482 output_asm_insn ("tsy", operands
);
3483 output_asm_insn ("sty\t%0", operands
);
3484 output_asm_insn ("ldy\t%t0", operands
);
3488 output_asm_insn ("stx\t%t0", operands
);
3489 output_asm_insn ("tsx", operands
);
3490 output_asm_insn ("stx\t%0", operands
);
3491 output_asm_insn ("ldx\t%t0", operands
);
3497 fatal_insn ("invalid register in the move instruction", insn
);
3503 m68hc11_gen_movqi (rtx insn
, rtx
*operands
)
3505 /* Move a register or memory to the same location.
3506 This is possible because such insn can appear
3507 in a non-optimizing mode. */
3508 if (operands
[0] == operands
[1] || rtx_equal_p (operands
[0], operands
[1]))
3510 cc_status
= cc_prev_status
;
3517 if (H_REG_P (operands
[0]) && H_REG_P (operands
[1]))
3519 m68hc11_notice_keep_cc (operands
[0]);
3520 output_asm_insn ("tfr\t%1,%0", operands
);
3522 else if (H_REG_P (operands
[0]))
3524 if (IS_STACK_POP (operands
[1]))
3525 output_asm_insn ("pul%b0", operands
);
3526 else if (Q_REG_P (operands
[0]))
3527 output_asm_insn ("lda%0\t%b1", operands
);
3528 else if (D_REG_P (operands
[0]))
3529 output_asm_insn ("ldab\t%b1", operands
);
3533 else if (H_REG_P (operands
[1]))
3535 if (Q_REG_P (operands
[1]))
3536 output_asm_insn ("sta%1\t%b0", operands
);
3537 else if (D_REG_P (operands
[1]))
3538 output_asm_insn ("stab\t%b0", operands
);
3544 rtx from
= operands
[1];
3545 rtx to
= operands
[0];
3547 if ((m68hc11_register_indirect_p (from
, GET_MODE (from
))
3548 && !m68hc11_small_indexed_indirect_p (from
, GET_MODE (from
)))
3549 || (m68hc11_register_indirect_p (to
, GET_MODE (to
))
3550 && !m68hc11_small_indexed_indirect_p (to
, GET_MODE (to
))))
3556 ops
[0] = operands
[2];
3559 m68hc11_gen_movqi (insn
, ops
);
3561 ops
[1] = operands
[2];
3562 m68hc11_gen_movqi (insn
, ops
);
3566 /* !!!! SCz wrong here. */
3567 fatal_insn ("move insn not handled", insn
);
3572 if (GET_CODE (from
) == CONST_INT
&& INTVAL (from
) == 0)
3574 output_asm_insn ("clr\t%b0", operands
);
3578 m68hc11_notice_keep_cc (operands
[0]);
3579 output_asm_insn ("movb\t%b1,%b0", operands
);
3587 if (H_REG_P (operands
[0]))
3589 switch (REGNO (operands
[0]))
3593 if (X_REG_P (operands
[1]))
3595 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_X_REGNUM
))
3597 m68hc11_output_swap (insn
, operands
);
3601 output_asm_insn ("stx\t%t1", operands
);
3602 output_asm_insn ("ldab\t%T0", operands
);
3605 else if (Y_REG_P (operands
[1]))
3607 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_Y_REGNUM
))
3609 m68hc11_output_swap (insn
, operands
);
3613 output_asm_insn ("sty\t%t1", operands
);
3614 output_asm_insn ("ldab\t%T0", operands
);
3617 else if (!DB_REG_P (operands
[1]) && !D_REG_P (operands
[1])
3618 && !DA_REG_P (operands
[1]))
3620 output_asm_insn ("ldab\t%b1", operands
);
3622 else if (DA_REG_P (operands
[1]))
3624 output_asm_insn ("tab", operands
);
3628 cc_status
= cc_prev_status
;
3634 if (X_REG_P (operands
[1]))
3636 output_asm_insn ("stx\t%t1", operands
);
3637 output_asm_insn ("ldaa\t%T0", operands
);
3639 else if (Y_REG_P (operands
[1]))
3641 output_asm_insn ("sty\t%t1", operands
);
3642 output_asm_insn ("ldaa\t%T0", operands
);
3644 else if (!DB_REG_P (operands
[1]) && !D_REG_P (operands
[1])
3645 && !DA_REG_P (operands
[1]))
3647 output_asm_insn ("ldaa\t%b1", operands
);
3649 else if (!DA_REG_P (operands
[1]))
3651 output_asm_insn ("tba", operands
);
3655 cc_status
= cc_prev_status
;
3660 if (D_REG_P (operands
[1]))
3662 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_D_REGNUM
))
3664 m68hc11_output_swap (insn
, operands
);
3668 output_asm_insn ("stab\t%T1", operands
);
3669 output_asm_insn ("ldx\t%t1", operands
);
3673 else if (Y_REG_P (operands
[1]))
3675 output_asm_insn ("sty\t%t0", operands
);
3676 output_asm_insn ("ldx\t%t0", operands
);
3678 else if (GET_CODE (operands
[1]) == CONST_INT
)
3680 output_asm_insn ("ldx\t%1", operands
);
3682 else if (dead_register_here (insn
, d_reg
))
3684 output_asm_insn ("ldab\t%b1", operands
);
3685 output_asm_insn ("xgdx", operands
);
3687 else if (!reg_mentioned_p (operands
[0], operands
[1]))
3689 output_asm_insn ("xgdx", operands
);
3690 output_asm_insn ("ldab\t%b1", operands
);
3691 output_asm_insn ("xgdx", operands
);
3695 output_asm_insn ("pshb", operands
);
3696 output_asm_insn ("ldab\t%b1", operands
);
3697 output_asm_insn ("stab\t%T1", operands
);
3698 output_asm_insn ("ldx\t%t1", operands
);
3699 output_asm_insn ("pulb", operands
);
3705 if (D_REG_P (operands
[1]))
3707 output_asm_insn ("stab\t%T1", operands
);
3708 output_asm_insn ("ldy\t%t1", operands
);
3711 else if (X_REG_P (operands
[1]))
3713 output_asm_insn ("stx\t%t1", operands
);
3714 output_asm_insn ("ldy\t%t1", operands
);
3717 else if (GET_CODE (operands
[1]) == CONST_INT
)
3719 output_asm_insn ("ldy\t%1", operands
);
3721 else if (dead_register_here (insn
, d_reg
))
3723 output_asm_insn ("ldab\t%b1", operands
);
3724 output_asm_insn ("xgdy", operands
);
3726 else if (!reg_mentioned_p (operands
[0], operands
[1]))
3728 output_asm_insn ("xgdy", operands
);
3729 output_asm_insn ("ldab\t%b1", operands
);
3730 output_asm_insn ("xgdy", operands
);
3734 output_asm_insn ("pshb", operands
);
3735 output_asm_insn ("ldab\t%b1", operands
);
3736 output_asm_insn ("stab\t%T1", operands
);
3737 output_asm_insn ("ldy\t%t1", operands
);
3738 output_asm_insn ("pulb", operands
);
3744 fatal_insn ("invalid register in the instruction", insn
);
3748 else if (H_REG_P (operands
[1]))
3750 switch (REGNO (operands
[1]))
3754 output_asm_insn ("stab\t%b0", operands
);
3758 output_asm_insn ("staa\t%b0", operands
);
3762 output_asm_insn ("xgdx\n\tstab\t%b0\n\txgdx", operands
);
3766 output_asm_insn ("xgdy\n\tstab\t%b0\n\txgdy", operands
);
3770 fatal_insn ("invalid register in the move instruction", insn
);
3777 fatal_insn ("operand 1 must be a hard register", insn
);
3781 /* Generate the code for a ROTATE or ROTATERT on a QI or HI mode.
3782 The source and destination must be D or A and the shift must
3785 m68hc11_gen_rotate (enum rtx_code code
, rtx insn
, rtx operands
[])
3789 if (GET_CODE (operands
[2]) != CONST_INT
3790 || (!D_REG_P (operands
[0]) && !DA_REG_P (operands
[0])))
3791 fatal_insn ("invalid rotate insn", insn
);
3793 val
= INTVAL (operands
[2]);
3794 if (code
== ROTATERT
)
3795 val
= GET_MODE_SIZE (GET_MODE (operands
[0])) * BITS_PER_UNIT
- val
;
3797 if (GET_MODE (operands
[0]) != QImode
)
3800 /* Rotate by 8-bits if the shift is within [5..11]. */
3801 if (val
>= 5 && val
<= 11)
3804 output_asm_insn ("exg\ta,b", operands
);
3807 output_asm_insn ("psha", operands
);
3808 output_asm_insn ("tba", operands
);
3809 output_asm_insn ("pulb", operands
);
3814 /* If the shift is big, invert the rotation. */
3824 /* Set the carry to bit-15, but don't change D yet. */
3825 if (GET_MODE (operands
[0]) != QImode
)
3827 output_asm_insn ("asra", operands
);
3828 output_asm_insn ("rola", operands
);
3831 /* Rotate B first to move the carry to bit-0. */
3832 if (D_REG_P (operands
[0]))
3833 output_asm_insn ("rolb", operands
);
3835 if (GET_MODE (operands
[0]) != QImode
|| DA_REG_P (operands
[0]))
3836 output_asm_insn ("rola", operands
);
3843 /* Set the carry to bit-8 of D. */
3844 if (GET_MODE (operands
[0]) != QImode
)
3845 output_asm_insn ("tap", operands
);
3847 /* Rotate B first to move the carry to bit-7. */
3848 if (D_REG_P (operands
[0]))
3849 output_asm_insn ("rorb", operands
);
3851 if (GET_MODE (operands
[0]) != QImode
|| DA_REG_P (operands
[0]))
3852 output_asm_insn ("rora", operands
);
3859 /* Store in cc_status the expressions that the condition codes will
3860 describe after execution of an instruction whose pattern is EXP.
3861 Do not alter them if the instruction would not alter the cc's. */
3864 m68hc11_notice_update_cc (rtx exp
, rtx insn ATTRIBUTE_UNUSED
)
3866 /* recognize SET insn's. */
3867 if (GET_CODE (exp
) == SET
)
3869 /* Jumps do not alter the cc's. */
3870 if (SET_DEST (exp
) == pc_rtx
)
3873 /* NOTE: most instructions don't affect the carry bit, but the
3874 bhi/bls/bhs/blo instructions use it. This isn't mentioned in
3875 the conditions.h header. */
3877 /* Function calls clobber the cc's. */
3878 else if (GET_CODE (SET_SRC (exp
)) == CALL
)
3883 /* Tests and compares set the cc's in predictable ways. */
3884 else if (SET_DEST (exp
) == cc0_rtx
)
3886 cc_status
.flags
= 0;
3887 cc_status
.value1
= XEXP (exp
, 0);
3888 cc_status
.value2
= XEXP (exp
, 1);
3892 /* All other instructions affect the condition codes. */
3893 cc_status
.flags
= 0;
3894 cc_status
.value1
= XEXP (exp
, 0);
3895 cc_status
.value2
= XEXP (exp
, 1);
3900 /* Default action if we haven't recognized something
3901 and returned earlier. */
3905 if (cc_status
.value2
!= 0)
3906 switch (GET_CODE (cc_status
.value2
))
3908 /* These logical operations can generate several insns.
3909 The flags are setup according to what is generated. */
3915 /* The (not ...) generates several 'com' instructions for
3916 non QImode. We have to invalidate the flags. */
3918 if (GET_MODE (cc_status
.value2
) != QImode
)
3930 if (GET_MODE (cc_status
.value2
) != VOIDmode
)
3931 cc_status
.flags
|= CC_NO_OVERFLOW
;
3934 /* The asl sets the overflow bit in such a way that this
3935 makes the flags unusable for a next compare insn. */
3939 if (GET_MODE (cc_status
.value2
) != VOIDmode
)
3940 cc_status
.flags
|= CC_NO_OVERFLOW
;
3943 /* A load/store instruction does not affect the carry. */
3948 cc_status
.flags
|= CC_NO_OVERFLOW
;
3954 if (cc_status
.value1
&& GET_CODE (cc_status
.value1
) == REG
3956 && reg_overlap_mentioned_p (cc_status
.value1
, cc_status
.value2
))
3957 cc_status
.value2
= 0;
3959 else if (cc_status
.value1
&& side_effects_p (cc_status
.value1
))
3960 cc_status
.value1
= 0;
3962 else if (cc_status
.value2
&& side_effects_p (cc_status
.value2
))
3963 cc_status
.value2
= 0;
3966 /* The current instruction does not affect the flags but changes
3967 the register 'reg'. See if the previous flags can be kept for the
3968 next instruction to avoid a comparison. */
3970 m68hc11_notice_keep_cc (rtx reg
)
3973 || cc_prev_status
.value1
== 0
3974 || rtx_equal_p (reg
, cc_prev_status
.value1
)
3975 || (cc_prev_status
.value2
3976 && reg_mentioned_p (reg
, cc_prev_status
.value2
)))
3979 cc_status
= cc_prev_status
;
3984 /* Machine Specific Reorg. */
3986 /* Z register replacement:
3988 GCC treats the Z register as an index base address register like
3989 X or Y. In general, it uses it during reload to compute the address
3990 of some operand. This helps the reload pass to avoid to fall into the
3991 register spill failure.
3993 The Z register is in the A_REGS class. In the machine description,
3994 the 'A' constraint matches it. The 'x' or 'y' constraints do not.
3996 It can appear everywhere an X or Y register can appear, except for
3997 some templates in the clobber section (when a clobber of X or Y is asked).
3998 For a given instruction, the template must ensure that no more than
3999 2 'A' registers are used. Otherwise, the register replacement is not
4002 To replace the Z register, the algorithm is not terrific:
4003 1. Insns that do not use the Z register are not changed
4004 2. When a Z register is used, we scan forward the insns to see
4005 a potential register to use: either X or Y and sometimes D.
4006 We stop when a call, a label or a branch is seen, or when we
4007 detect that both X and Y are used (probably at different times, but it does
4009 3. The register that will be used for the replacement of Z is saved
4010 in a .page0 register or on the stack. If the first instruction that
4011 used Z, uses Z as an input, the value is loaded from another .page0
4012 register. The replacement register is pushed on the stack in the
4013 rare cases where a compare insn uses Z and we couldn't find if X/Y
4015 4. The Z register is replaced in all instructions until we reach
4016 the end of the Z-block, as detected by step 2.
4017 5. If we detect that Z is still alive, its value is saved.
4018 If the replacement register is alive, its old value is loaded.
4020 The Z register can be disabled with -ffixed-z.
4030 int must_restore_reg
;
4041 int save_before_last
;
4042 int z_loaded_with_sp
;
4045 static int m68hc11_check_z_replacement (rtx
, struct replace_info
*);
4046 static void m68hc11_find_z_replacement (rtx
, struct replace_info
*);
4047 static void m68hc11_z_replacement (rtx
);
4048 static void m68hc11_reassign_regs (rtx
);
4050 int z_replacement_completed
= 0;
4052 /* Analyze the insn to find out which replacement register to use and
4053 the boundaries of the replacement.
4054 Returns 0 if we reached the last insn to be replaced, 1 if we can
4055 continue replacement in next insns. */
4058 m68hc11_check_z_replacement (rtx insn
, struct replace_info
*info
)
4060 int this_insn_uses_ix
;
4061 int this_insn_uses_iy
;
4062 int this_insn_uses_z
;
4063 int this_insn_uses_z_in_dst
;
4064 int this_insn_uses_d
;
4068 /* A call is said to clobber the Z register, we don't need
4069 to save the value of Z. We also don't need to restore
4070 the replacement register (unless it is used by the call). */
4071 if (GET_CODE (insn
) == CALL_INSN
)
4073 body
= PATTERN (insn
);
4075 info
->can_use_d
= 0;
4077 /* If the call is an indirect call with Z, we have to use the
4078 Y register because X can be used as an input (D+X).
4079 We also must not save Z nor restore Y. */
4080 if (reg_mentioned_p (z_reg
, body
))
4082 insn
= NEXT_INSN (insn
);
4085 info
->found_call
= 1;
4086 info
->must_restore_reg
= 0;
4087 info
->last
= NEXT_INSN (insn
);
4089 info
->need_save_z
= 0;
4092 if (GET_CODE (insn
) == CODE_LABEL
4093 || GET_CODE (insn
) == BARRIER
|| GET_CODE (insn
) == ASM_INPUT
)
4096 if (GET_CODE (insn
) == JUMP_INSN
)
4098 if (reg_mentioned_p (z_reg
, insn
) == 0)
4101 info
->can_use_d
= 0;
4102 info
->must_save_reg
= 0;
4103 info
->must_restore_reg
= 0;
4104 info
->need_save_z
= 0;
4105 info
->last
= NEXT_INSN (insn
);
4108 if (GET_CODE (insn
) != INSN
&& GET_CODE (insn
) != JUMP_INSN
)
4113 /* Z register dies here. */
4114 z_dies_here
= find_regno_note (insn
, REG_DEAD
, HARD_Z_REGNUM
) != NULL
;
4116 body
= PATTERN (insn
);
4117 if (GET_CODE (body
) == SET
)
4119 rtx src
= XEXP (body
, 1);
4120 rtx dst
= XEXP (body
, 0);
4122 /* Condition code is set here. We have to restore the X/Y and
4123 save into Z before any test/compare insn because once we save/restore
4124 we can change the condition codes. When the compare insn uses Z and
4125 we can't use X/Y, the comparison is made with the *ZREG soft register
4126 (this is supported by cmphi, cmpqi, tsthi, tstqi patterns). */
4129 if ((GET_CODE (src
) == REG
&& REGNO (src
) == HARD_Z_REGNUM
)
4130 || (GET_CODE (src
) == COMPARE
&&
4131 ((rtx_equal_p (XEXP (src
, 0), z_reg
)
4132 && H_REG_P (XEXP (src
, 1)))
4133 || (rtx_equal_p (XEXP (src
, 1), z_reg
)
4134 && H_REG_P (XEXP (src
, 0))))))
4136 if (insn
== info
->first
)
4138 info
->must_load_z
= 0;
4139 info
->must_save_reg
= 0;
4140 info
->must_restore_reg
= 0;
4141 info
->need_save_z
= 0;
4142 info
->found_call
= 1;
4143 info
->regno
= SOFT_Z_REGNUM
;
4144 info
->last
= NEXT_INSN (insn
);
4148 if (reg_mentioned_p (z_reg
, src
) == 0)
4150 info
->can_use_d
= 0;
4154 if (insn
!= info
->first
)
4157 /* Compare insn which uses Z. We have to save/restore the X/Y
4158 register without modifying the condition codes. For this
4159 we have to use a push/pop insn. */
4160 info
->must_push_reg
= 1;
4164 /* Z reg is set to something new. We don't need to load it. */
4167 if (!reg_mentioned_p (z_reg
, src
))
4169 /* Z reg is used before being set. Treat this as
4170 a new sequence of Z register replacement. */
4171 if (insn
!= info
->first
)
4175 info
->must_load_z
= 0;
4177 info
->z_set_count
++;
4178 info
->z_value
= src
;
4180 info
->z_loaded_with_sp
= 1;
4182 else if (reg_mentioned_p (z_reg
, dst
))
4183 info
->can_use_d
= 0;
4185 this_insn_uses_d
= reg_mentioned_p (d_reg
, src
)
4186 | reg_mentioned_p (d_reg
, dst
);
4187 this_insn_uses_ix
= reg_mentioned_p (ix_reg
, src
)
4188 | reg_mentioned_p (ix_reg
, dst
);
4189 this_insn_uses_iy
= reg_mentioned_p (iy_reg
, src
)
4190 | reg_mentioned_p (iy_reg
, dst
);
4191 this_insn_uses_z
= reg_mentioned_p (z_reg
, src
);
4193 /* If z is used as an address operand (like (MEM (reg z))),
4194 we can't replace it with d. */
4195 if (this_insn_uses_z
&& !Z_REG_P (src
)
4196 && !(m68hc11_arith_operator (src
, GET_MODE (src
))
4197 && Z_REG_P (XEXP (src
, 0))
4198 && !reg_mentioned_p (z_reg
, XEXP (src
, 1))
4199 && insn
== info
->first
4200 && dead_register_here (insn
, d_reg
)))
4201 info
->can_use_d
= 0;
4203 this_insn_uses_z_in_dst
= reg_mentioned_p (z_reg
, dst
);
4204 if (TARGET_M6812
&& !z_dies_here
4205 && ((this_insn_uses_z
&& side_effects_p (src
))
4206 || (this_insn_uses_z_in_dst
&& side_effects_p (dst
))))
4208 info
->need_save_z
= 1;
4209 info
->z_set_count
++;
4211 this_insn_uses_z
|= this_insn_uses_z_in_dst
;
4213 if (this_insn_uses_z
&& this_insn_uses_ix
&& this_insn_uses_iy
)
4215 fatal_insn ("registers IX, IY and Z used in the same INSN", insn
);
4218 if (this_insn_uses_d
)
4219 info
->can_use_d
= 0;
4221 /* IX and IY are used at the same time, we have to restore
4222 the value of the scratch register before this insn. */
4223 if (this_insn_uses_ix
&& this_insn_uses_iy
)
4228 if (this_insn_uses_ix
&& X_REG_P (dst
) && GET_MODE (dst
) == SImode
)
4229 info
->can_use_d
= 0;
4231 if (info
->x_used
== 0 && this_insn_uses_ix
)
4235 /* We have a (set (REG:HI X) (REG:HI Z)).
4236 Since we use Z as the replacement register, this insn
4237 is no longer necessary. We turn it into a note. We must
4238 not reload the old value of X. */
4239 if (X_REG_P (dst
) && rtx_equal_p (src
, z_reg
))
4243 info
->need_save_z
= 0;
4246 info
->must_save_reg
= 0;
4247 info
->must_restore_reg
= 0;
4248 info
->found_call
= 1;
4249 info
->can_use_d
= 0;
4250 PUT_CODE (insn
, NOTE
);
4251 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
4252 NOTE_SOURCE_FILE (insn
) = 0;
4253 info
->last
= NEXT_INSN (insn
);
4258 && (rtx_equal_p (src
, z_reg
)
4259 || (z_dies_here
&& !reg_mentioned_p (ix_reg
, src
))))
4263 info
->need_save_z
= 0;
4266 info
->last
= NEXT_INSN (insn
);
4267 info
->must_save_reg
= 0;
4268 info
->must_restore_reg
= 0;
4270 else if (X_REG_P (dst
) && reg_mentioned_p (z_reg
, src
)
4271 && !reg_mentioned_p (ix_reg
, src
))
4276 info
->need_save_z
= 0;
4278 else if (TARGET_M6812
&& side_effects_p (src
))
4281 info
->must_restore_reg
= 0;
4286 info
->save_before_last
= 1;
4288 info
->must_restore_reg
= 0;
4289 info
->last
= NEXT_INSN (insn
);
4291 else if (info
->can_use_d
)
4293 info
->last
= NEXT_INSN (insn
);
4299 if (z_dies_here
&& !reg_mentioned_p (ix_reg
, src
)
4300 && GET_CODE (dst
) == REG
&& REGNO (dst
) == HARD_X_REGNUM
)
4302 info
->need_save_z
= 0;
4304 info
->last
= NEXT_INSN (insn
);
4305 info
->regno
= HARD_X_REGNUM
;
4306 info
->must_save_reg
= 0;
4307 info
->must_restore_reg
= 0;
4310 if (rtx_equal_p (src
, z_reg
) && rtx_equal_p (dst
, ix_reg
))
4312 info
->regno
= HARD_X_REGNUM
;
4313 info
->must_restore_reg
= 0;
4314 info
->must_save_reg
= 0;
4318 if (info
->y_used
== 0 && this_insn_uses_iy
)
4322 if (Y_REG_P (dst
) && rtx_equal_p (src
, z_reg
))
4326 info
->need_save_z
= 0;
4329 info
->must_save_reg
= 0;
4330 info
->must_restore_reg
= 0;
4331 info
->found_call
= 1;
4332 info
->can_use_d
= 0;
4333 PUT_CODE (insn
, NOTE
);
4334 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
4335 NOTE_SOURCE_FILE (insn
) = 0;
4336 info
->last
= NEXT_INSN (insn
);
4341 && (rtx_equal_p (src
, z_reg
)
4342 || (z_dies_here
&& !reg_mentioned_p (iy_reg
, src
))))
4347 info
->need_save_z
= 0;
4349 info
->last
= NEXT_INSN (insn
);
4350 info
->must_save_reg
= 0;
4351 info
->must_restore_reg
= 0;
4353 else if (Y_REG_P (dst
) && reg_mentioned_p (z_reg
, src
)
4354 && !reg_mentioned_p (iy_reg
, src
))
4359 info
->need_save_z
= 0;
4361 else if (TARGET_M6812
&& side_effects_p (src
))
4364 info
->must_restore_reg
= 0;
4369 info
->save_before_last
= 1;
4371 info
->must_restore_reg
= 0;
4372 info
->last
= NEXT_INSN (insn
);
4374 else if (info
->can_use_d
)
4376 info
->last
= NEXT_INSN (insn
);
4383 if (z_dies_here
&& !reg_mentioned_p (iy_reg
, src
)
4384 && GET_CODE (dst
) == REG
&& REGNO (dst
) == HARD_Y_REGNUM
)
4386 info
->need_save_z
= 0;
4388 info
->last
= NEXT_INSN (insn
);
4389 info
->regno
= HARD_Y_REGNUM
;
4390 info
->must_save_reg
= 0;
4391 info
->must_restore_reg
= 0;
4394 if (rtx_equal_p (src
, z_reg
) && rtx_equal_p (dst
, iy_reg
))
4396 info
->regno
= HARD_Y_REGNUM
;
4397 info
->must_restore_reg
= 0;
4398 info
->must_save_reg
= 0;
4404 info
->need_save_z
= 0;
4406 if (info
->last
== 0)
4407 info
->last
= NEXT_INSN (insn
);
4410 return info
->last
!= NULL_RTX
? 0 : 1;
4412 if (GET_CODE (body
) == PARALLEL
)
4415 char ix_clobber
= 0;
4416 char iy_clobber
= 0;
4418 this_insn_uses_iy
= 0;
4419 this_insn_uses_ix
= 0;
4420 this_insn_uses_z
= 0;
4422 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
4425 int uses_ix
, uses_iy
, uses_z
;
4427 x
= XVECEXP (body
, 0, i
);
4429 if (info
->can_use_d
&& reg_mentioned_p (d_reg
, x
))
4430 info
->can_use_d
= 0;
4432 uses_ix
= reg_mentioned_p (ix_reg
, x
);
4433 uses_iy
= reg_mentioned_p (iy_reg
, x
);
4434 uses_z
= reg_mentioned_p (z_reg
, x
);
4435 if (GET_CODE (x
) == CLOBBER
)
4437 ix_clobber
|= uses_ix
;
4438 iy_clobber
|= uses_iy
;
4439 z_clobber
|= uses_z
;
4443 this_insn_uses_ix
|= uses_ix
;
4444 this_insn_uses_iy
|= uses_iy
;
4445 this_insn_uses_z
|= uses_z
;
4447 if (uses_z
&& GET_CODE (x
) == SET
)
4449 rtx dst
= XEXP (x
, 0);
4452 info
->z_set_count
++;
4454 if (TARGET_M6812
&& uses_z
&& side_effects_p (x
))
4455 info
->need_save_z
= 1;
4458 info
->need_save_z
= 0;
4462 printf ("Uses X:%d Y:%d Z:%d CX:%d CY:%d CZ:%d\n",
4463 this_insn_uses_ix
, this_insn_uses_iy
,
4464 this_insn_uses_z
, ix_clobber
, iy_clobber
, z_clobber
);
4467 if (this_insn_uses_z
)
4468 info
->can_use_d
= 0;
4470 if (z_clobber
&& info
->first
!= insn
)
4472 info
->need_save_z
= 0;
4476 if (z_clobber
&& info
->x_used
== 0 && info
->y_used
== 0)
4478 if (this_insn_uses_z
== 0 && insn
== info
->first
)
4480 info
->must_load_z
= 0;
4482 if (dead_register_here (insn
, d_reg
))
4484 info
->regno
= HARD_D_REGNUM
;
4485 info
->must_save_reg
= 0;
4486 info
->must_restore_reg
= 0;
4488 else if (dead_register_here (insn
, ix_reg
))
4490 info
->regno
= HARD_X_REGNUM
;
4491 info
->must_save_reg
= 0;
4492 info
->must_restore_reg
= 0;
4494 else if (dead_register_here (insn
, iy_reg
))
4496 info
->regno
= HARD_Y_REGNUM
;
4497 info
->must_save_reg
= 0;
4498 info
->must_restore_reg
= 0;
4500 if (info
->regno
>= 0)
4502 info
->last
= NEXT_INSN (insn
);
4505 if (this_insn_uses_ix
== 0)
4507 info
->regno
= HARD_X_REGNUM
;
4508 info
->must_save_reg
= 1;
4509 info
->must_restore_reg
= 1;
4511 else if (this_insn_uses_iy
== 0)
4513 info
->regno
= HARD_Y_REGNUM
;
4514 info
->must_save_reg
= 1;
4515 info
->must_restore_reg
= 1;
4519 info
->regno
= HARD_D_REGNUM
;
4520 info
->must_save_reg
= 1;
4521 info
->must_restore_reg
= 1;
4523 info
->last
= NEXT_INSN (insn
);
4527 if (((info
->x_used
|| this_insn_uses_ix
) && iy_clobber
)
4528 || ((info
->y_used
|| this_insn_uses_iy
) && ix_clobber
))
4530 if (this_insn_uses_z
)
4532 if (info
->y_used
== 0 && iy_clobber
)
4534 info
->regno
= HARD_Y_REGNUM
;
4535 info
->must_save_reg
= 0;
4536 info
->must_restore_reg
= 0;
4538 if (info
->first
!= insn
4539 && ((info
->y_used
&& ix_clobber
)
4540 || (info
->x_used
&& iy_clobber
)))
4543 info
->last
= NEXT_INSN (insn
);
4544 info
->save_before_last
= 1;
4548 if (this_insn_uses_ix
&& this_insn_uses_iy
)
4550 if (this_insn_uses_z
)
4552 fatal_insn ("cannot do z-register replacement", insn
);
4556 if (info
->x_used
== 0 && (this_insn_uses_ix
|| ix_clobber
))
4563 if (iy_clobber
|| z_clobber
)
4565 info
->last
= NEXT_INSN (insn
);
4566 info
->save_before_last
= 1;
4571 if (info
->y_used
== 0 && (this_insn_uses_iy
|| iy_clobber
))
4578 if (ix_clobber
|| z_clobber
)
4580 info
->last
= NEXT_INSN (insn
);
4581 info
->save_before_last
= 1;
4588 info
->need_save_z
= 0;
4592 if (GET_CODE (body
) == CLOBBER
)
4595 /* IX and IY are used at the same time, we have to restore
4596 the value of the scratch register before this insn. */
4597 if (this_insn_uses_ix
&& this_insn_uses_iy
)
4601 if (info
->x_used
== 0 && this_insn_uses_ix
)
4609 if (info
->y_used
== 0 && this_insn_uses_iy
)
4623 m68hc11_find_z_replacement (rtx insn
, struct replace_info
*info
)
4627 info
->replace_reg
= NULL_RTX
;
4628 info
->must_load_z
= 1;
4629 info
->need_save_z
= 1;
4630 info
->must_save_reg
= 1;
4631 info
->must_restore_reg
= 1;
4635 info
->can_use_d
= TARGET_M6811
? 1 : 0;
4636 info
->found_call
= 0;
4640 info
->z_set_count
= 0;
4641 info
->z_value
= NULL_RTX
;
4642 info
->must_push_reg
= 0;
4643 info
->save_before_last
= 0;
4644 info
->z_loaded_with_sp
= 0;
4646 /* Scan the insn forward to find an address register that is not used.
4648 - the flow of the program changes,
4649 - when we detect that both X and Y are necessary,
4650 - when the Z register dies,
4651 - when the condition codes are set. */
4653 for (; insn
&& info
->z_died
== 0; insn
= NEXT_INSN (insn
))
4655 if (m68hc11_check_z_replacement (insn
, info
) == 0)
4659 /* May be we can use Y or X if they contain the same value as Z.
4660 This happens very often after the reload. */
4661 if (info
->z_set_count
== 1)
4663 rtx p
= info
->first
;
4668 v
= find_last_value (iy_reg
, &p
, insn
, 1);
4670 else if (info
->y_used
)
4672 v
= find_last_value (ix_reg
, &p
, insn
, 1);
4674 if (v
&& (v
!= iy_reg
&& v
!= ix_reg
) && rtx_equal_p (v
, info
->z_value
))
4677 info
->regno
= HARD_Y_REGNUM
;
4679 info
->regno
= HARD_X_REGNUM
;
4680 info
->must_load_z
= 0;
4681 info
->must_save_reg
= 0;
4682 info
->must_restore_reg
= 0;
4683 info
->found_call
= 1;
4686 if (info
->z_set_count
== 0)
4687 info
->need_save_z
= 0;
4690 info
->need_save_z
= 0;
4692 if (info
->last
== 0)
4695 if (info
->regno
>= 0)
4698 info
->replace_reg
= gen_rtx_REG (HImode
, reg
);
4700 else if (info
->can_use_d
)
4702 reg
= HARD_D_REGNUM
;
4703 info
->replace_reg
= d_reg
;
4705 else if (info
->x_used
)
4707 reg
= HARD_Y_REGNUM
;
4708 info
->replace_reg
= iy_reg
;
4712 reg
= HARD_X_REGNUM
;
4713 info
->replace_reg
= ix_reg
;
4717 if (info
->must_save_reg
&& info
->must_restore_reg
)
4719 if (insn
&& dead_register_here (insn
, info
->replace_reg
))
4721 info
->must_save_reg
= 0;
4722 info
->must_restore_reg
= 0;
4727 /* The insn uses the Z register. Find a replacement register for it
4728 (either X or Y) and replace it in the insn and the next ones until
4729 the flow changes or the replacement register is used. Instructions
4730 are emitted before and after the Z-block to preserve the value of
4731 Z and of the replacement register. */
4734 m68hc11_z_replacement (rtx insn
)
4738 struct replace_info info
;
4740 /* Find trivial case where we only need to replace z with the
4741 equivalent soft register. */
4742 if (GET_CODE (insn
) == INSN
&& GET_CODE (PATTERN (insn
)) == SET
)
4744 rtx body
= PATTERN (insn
);
4745 rtx src
= XEXP (body
, 1);
4746 rtx dst
= XEXP (body
, 0);
4748 if (Z_REG_P (dst
) && (H_REG_P (src
) && !SP_REG_P (src
)))
4750 XEXP (body
, 0) = gen_rtx_REG (GET_MODE (dst
), SOFT_Z_REGNUM
);
4753 else if (Z_REG_P (src
)
4754 && ((H_REG_P (dst
) && !SP_REG_P (src
)) || dst
== cc0_rtx
))
4756 XEXP (body
, 1) = gen_rtx_REG (GET_MODE (src
), SOFT_Z_REGNUM
);
4759 else if (D_REG_P (dst
)
4760 && m68hc11_arith_operator (src
, GET_MODE (src
))
4761 && D_REG_P (XEXP (src
, 0)) && Z_REG_P (XEXP (src
, 1)))
4763 XEXP (src
, 1) = gen_rtx_REG (GET_MODE (src
), SOFT_Z_REGNUM
);
4766 else if (Z_REG_P (dst
) && GET_CODE (src
) == CONST_INT
4767 && INTVAL (src
) == 0)
4769 XEXP (body
, 0) = gen_rtx_REG (GET_MODE (dst
), SOFT_Z_REGNUM
);
4770 /* Force it to be re-recognized. */
4771 INSN_CODE (insn
) = -1;
4776 m68hc11_find_z_replacement (insn
, &info
);
4778 replace_reg
= info
.replace_reg
;
4779 replace_reg_qi
= NULL_RTX
;
4781 /* Save the X register in a .page0 location. */
4782 if (info
.must_save_reg
&& !info
.must_push_reg
)
4786 if (info
.must_push_reg
&& 0)
4787 dst
= gen_rtx_MEM (HImode
,
4788 gen_rtx_PRE_DEC (HImode
,
4789 gen_rtx_REG (HImode
, HARD_SP_REGNUM
)));
4791 dst
= gen_rtx_REG (HImode
, SOFT_SAVED_XY_REGNUM
);
4793 emit_insn_before (gen_movhi (dst
,
4794 gen_rtx_REG (HImode
, info
.regno
)), insn
);
4796 if (info
.must_load_z
&& !info
.must_push_reg
)
4798 emit_insn_before (gen_movhi (gen_rtx_REG (HImode
, info
.regno
),
4799 gen_rtx_REG (HImode
, SOFT_Z_REGNUM
)),
4804 /* Replace all occurrence of Z by replace_reg.
4805 Stop when the last instruction to replace is reached.
4806 Also stop when we detect a change in the flow (but it's not
4807 necessary; just safeguard). */
4809 for (; insn
&& insn
!= info
.last
; insn
= NEXT_INSN (insn
))
4813 if (GET_CODE (insn
) == CODE_LABEL
|| GET_CODE (insn
) == BARRIER
)
4816 if (GET_CODE (insn
) != INSN
4817 && GET_CODE (insn
) != CALL_INSN
&& GET_CODE (insn
) != JUMP_INSN
)
4820 body
= PATTERN (insn
);
4821 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == PARALLEL
4822 || GET_CODE (body
) == ASM_OPERANDS
4823 || GET_CODE (insn
) == CALL_INSN
|| GET_CODE (insn
) == JUMP_INSN
)
4827 if (debug_m6811
&& reg_mentioned_p (replace_reg
, body
))
4829 printf ("Reg mentioned here...:\n");
4834 /* Stack pointer was decremented by 2 due to the push.
4835 Correct that by adding 2 to the destination. */
4836 if (info
.must_push_reg
4837 && info
.z_loaded_with_sp
&& GET_CODE (body
) == SET
)
4841 src
= SET_SRC (body
);
4842 dst
= SET_DEST (body
);
4843 if (SP_REG_P (src
) && Z_REG_P (dst
))
4844 emit_insn_after (gen_addhi3 (dst
, dst
, const2_rtx
), insn
);
4847 /* Replace any (REG:HI Z) occurrence by either X or Y. */
4848 if (!validate_replace_rtx (z_reg
, replace_reg
, insn
))
4850 INSN_CODE (insn
) = -1;
4851 if (!validate_replace_rtx (z_reg
, replace_reg
, insn
))
4852 fatal_insn ("cannot do z-register replacement", insn
);
4855 /* Likewise for (REG:QI Z). */
4856 if (reg_mentioned_p (z_reg
, insn
))
4858 if (replace_reg_qi
== NULL_RTX
)
4859 replace_reg_qi
= gen_rtx_REG (QImode
, REGNO (replace_reg
));
4860 validate_replace_rtx (z_reg_qi
, replace_reg_qi
, insn
);
4863 /* If there is a REG_INC note on Z, replace it with a
4864 REG_INC note on the replacement register. This is necessary
4865 to make sure that the flow pass will identify the change
4866 and it will not remove a possible insn that saves Z. */
4867 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
4869 if (REG_NOTE_KIND (note
) == REG_INC
4870 && GET_CODE (XEXP (note
, 0)) == REG
4871 && REGNO (XEXP (note
, 0)) == REGNO (z_reg
))
4873 XEXP (note
, 0) = replace_reg
;
4877 if (GET_CODE (insn
) == CALL_INSN
|| GET_CODE (insn
) == JUMP_INSN
)
4881 /* Save Z before restoring the old value. */
4882 if (insn
&& info
.need_save_z
&& !info
.must_push_reg
)
4884 rtx save_pos_insn
= insn
;
4886 /* If Z is clobber by the last insn, we have to save its value
4887 before the last instruction. */
4888 if (info
.save_before_last
)
4889 save_pos_insn
= PREV_INSN (save_pos_insn
);
4891 emit_insn_before (gen_movhi (gen_rtx_REG (HImode
, SOFT_Z_REGNUM
),
4892 gen_rtx_REG (HImode
, info
.regno
)),
4896 if (info
.must_push_reg
&& info
.last
)
4900 body
= PATTERN (info
.last
);
4901 new_body
= gen_rtx_PARALLEL (VOIDmode
,
4903 gen_rtx_USE (VOIDmode
,
4905 gen_rtx_USE (VOIDmode
,
4906 gen_rtx_REG (HImode
,
4908 PATTERN (info
.last
) = new_body
;
4910 /* Force recognition on insn since we changed it. */
4911 INSN_CODE (insn
) = -1;
4913 if (!validate_replace_rtx (z_reg
, replace_reg
, info
.last
))
4915 fatal_insn ("invalid Z register replacement for insn", insn
);
4917 insn
= NEXT_INSN (info
.last
);
4920 /* Restore replacement register unless it was died. */
4921 if (insn
&& info
.must_restore_reg
&& !info
.must_push_reg
)
4925 if (info
.must_push_reg
&& 0)
4926 dst
= gen_rtx_MEM (HImode
,
4927 gen_rtx_POST_INC (HImode
,
4928 gen_rtx_REG (HImode
, HARD_SP_REGNUM
)));
4930 dst
= gen_rtx_REG (HImode
, SOFT_SAVED_XY_REGNUM
);
4932 emit_insn_before (gen_movhi (gen_rtx_REG (HImode
, info
.regno
),
4939 /* Scan all the insn and re-affects some registers
4940 - The Z register (if it was used), is affected to X or Y depending
4941 on the instruction. */
4944 m68hc11_reassign_regs (rtx first
)
4948 ix_reg
= gen_rtx_REG (HImode
, HARD_X_REGNUM
);
4949 iy_reg
= gen_rtx_REG (HImode
, HARD_Y_REGNUM
);
4950 z_reg
= gen_rtx_REG (HImode
, HARD_Z_REGNUM
);
4951 z_reg_qi
= gen_rtx_REG (QImode
, HARD_Z_REGNUM
);
4953 /* Scan all insns to replace Z by X or Y preserving the old value
4954 of X/Y and restoring it afterward. */
4956 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
4960 if (GET_CODE (insn
) == CODE_LABEL
4961 || GET_CODE (insn
) == NOTE
|| GET_CODE (insn
) == BARRIER
)
4967 body
= PATTERN (insn
);
4968 if (GET_CODE (body
) == CLOBBER
|| GET_CODE (body
) == USE
)
4971 if (GET_CODE (body
) == CONST_INT
|| GET_CODE (body
) == ASM_INPUT
4972 || GET_CODE (body
) == ASM_OPERANDS
4973 || GET_CODE (body
) == UNSPEC
|| GET_CODE (body
) == UNSPEC_VOLATILE
)
4976 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == PARALLEL
4977 || GET_CODE (insn
) == CALL_INSN
|| GET_CODE (insn
) == JUMP_INSN
)
4980 /* If Z appears in this insn, replace it in the current insn
4981 and the next ones until the flow changes or we have to
4982 restore back the replacement register. */
4984 if (reg_mentioned_p (z_reg
, body
))
4986 m68hc11_z_replacement (insn
);
4991 printf ("insn not handled by Z replacement:\n");
4999 /* Machine-dependent reorg pass.
5000 Specific optimizations are defined here:
5001 - this pass changes the Z register into either X or Y
5002 (it preserves X/Y previous values in a memory slot in page0).
5004 When this pass is finished, the global variable
5005 'z_replacement_completed' is set to 2. */
5008 m68hc11_reorg (void)
5013 z_replacement_completed
= 0;
5014 z_reg
= gen_rtx_REG (HImode
, HARD_Z_REGNUM
);
5015 first
= get_insns ();
5017 /* Some RTX are shared at this point. This breaks the Z register
5018 replacement, unshare everything. */
5019 unshare_all_rtl_again (first
);
5021 /* Force a split of all splittable insn. This is necessary for the
5022 Z register replacement mechanism because we end up with basic insns. */
5023 split_all_insns_noflow ();
5026 z_replacement_completed
= 1;
5027 m68hc11_reassign_regs (first
);
5030 compute_bb_for_insn ();
5032 /* After some splitting, there are some opportunities for CSE pass.
5033 This happens quite often when 32-bit or above patterns are split. */
5034 if (optimize
> 0 && split_done
)
5036 reload_cse_regs (first
);
5039 /* Re-create the REG_DEAD notes. These notes are used in the machine
5040 description to use the best assembly directives. */
5043 /* Before recomputing the REG_DEAD notes, remove all of them.
5044 This is necessary because the reload_cse_regs() pass can
5045 have replaced some (MEM) with a register. In that case,
5046 the REG_DEAD that could exist for that register may become
5048 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
5054 pnote
= ®_NOTES (insn
);
5057 if (REG_NOTE_KIND (*pnote
) == REG_DEAD
)
5058 *pnote
= XEXP (*pnote
, 1);
5060 pnote
= &XEXP (*pnote
, 1);
5065 life_analysis (0, PROP_REG_INFO
| PROP_DEATH_NOTES
);
5068 z_replacement_completed
= 2;
5070 /* If optimizing, then go ahead and split insns that must be
5071 split after Z register replacement. This gives more opportunities
5072 for peephole (in particular for consecutives xgdx/xgdy). */
5074 split_all_insns_noflow ();
5076 /* Once insns are split after the z_replacement_completed == 2,
5077 we must not re-run the life_analysis. The xgdx/xgdy patterns
5078 are not recognized and the life_analysis pass removes some
5079 insns because it thinks some (SETs) are noops or made to dead
5080 stores (which is false due to the swap).
5082 Do a simple pass to eliminate the noop set that the final
5083 split could generate (because it was easier for split definition). */
5087 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
5091 if (INSN_DELETED_P (insn
))
5096 /* Remove the (set (R) (R)) insns generated by some splits. */
5097 body
= PATTERN (insn
);
5098 if (GET_CODE (body
) == SET
5099 && rtx_equal_p (SET_SRC (body
), SET_DEST (body
)))
5101 PUT_CODE (insn
, NOTE
);
5102 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
5103 NOTE_SOURCE_FILE (insn
) = 0;
5110 /* Override memcpy */
5113 m68hc11_init_libfuncs (void)
5115 memcpy_libfunc
= init_one_libfunc ("__memcpy");
5116 memcmp_libfunc
= init_one_libfunc ("__memcmp");
5117 memset_libfunc
= init_one_libfunc ("__memset");
5122 /* Cost functions. */
5124 /* Cost of moving memory. */
5126 m68hc11_memory_move_cost (enum machine_mode mode
, enum reg_class
class,
5127 int in ATTRIBUTE_UNUSED
)
5129 if (class <= H_REGS
&& class > NO_REGS
)
5131 if (GET_MODE_SIZE (mode
) <= 2)
5132 return COSTS_N_INSNS (1) + (reload_completed
| reload_in_progress
);
5134 return COSTS_N_INSNS (2) + (reload_completed
| reload_in_progress
);
5138 if (GET_MODE_SIZE (mode
) <= 2)
5139 return COSTS_N_INSNS (3);
5141 return COSTS_N_INSNS (4);
5146 /* Cost of moving data from a register of class 'from' to on in class 'to'.
5147 Reload does not check the constraint of set insns when the two registers
5148 have a move cost of 2. Setting a higher cost will force reload to check
5151 m68hc11_register_move_cost (enum machine_mode mode
, enum reg_class from
,
5154 /* All costs are symmetric, so reduce cases by putting the
5155 lower number class as the destination. */
5158 enum reg_class tmp
= to
;
5159 to
= from
, from
= tmp
;
5162 return m68hc11_memory_move_cost (mode
, S_REGS
, 0);
5163 else if (from
<= S_REGS
)
5164 return COSTS_N_INSNS (1) + (reload_completed
| reload_in_progress
);
5166 return COSTS_N_INSNS (2);
5170 /* Provide the costs of an addressing mode that contains ADDR.
5171 If ADDR is not a valid address, its cost is irrelevant. */
5174 m68hc11_address_cost (rtx addr
)
5178 switch (GET_CODE (addr
))
5181 /* Make the cost of hard registers and specially SP, FP small. */
5182 if (REGNO (addr
) < FIRST_PSEUDO_REGISTER
)
5199 register rtx plus0
= XEXP (addr
, 0);
5200 register rtx plus1
= XEXP (addr
, 1);
5202 if (GET_CODE (plus0
) != REG
)
5205 switch (GET_CODE (plus1
))
5208 if (INTVAL (plus1
) >= 2 * m68hc11_max_offset
5209 || INTVAL (plus1
) < m68hc11_min_offset
)
5211 else if (INTVAL (plus1
) >= m68hc11_max_offset
)
5215 if (REGNO (plus0
) < FIRST_PSEUDO_REGISTER
)
5237 if (SP_REG_P (XEXP (addr
, 0)))
5246 printf ("Address cost: %d for :", cost
);
5255 m68hc11_shift_cost (enum machine_mode mode
, rtx x
, int shift
)
5259 total
= rtx_cost (x
, SET
);
5261 total
+= m68hc11_cost
->shiftQI_const
[shift
% 8];
5262 else if (mode
== HImode
)
5263 total
+= m68hc11_cost
->shiftHI_const
[shift
% 16];
5264 else if (shift
== 8 || shift
== 16 || shift
== 32)
5265 total
+= m68hc11_cost
->shiftHI_const
[8];
5266 else if (shift
!= 0 && shift
!= 16 && shift
!= 32)
5268 total
+= m68hc11_cost
->shiftHI_const
[1] * shift
;
5271 /* For SI and others, the cost is higher. */
5272 if (GET_MODE_SIZE (mode
) > 2 && (shift
% 16) != 0)
5273 total
*= GET_MODE_SIZE (mode
) / 2;
5275 /* When optimizing for size, make shift more costly so that
5276 multiplications are preferred. */
5277 if (optimize_size
&& (shift
% 8) != 0)
5284 m68hc11_rtx_costs_1 (rtx x
, enum rtx_code code
,
5285 enum rtx_code outer_code ATTRIBUTE_UNUSED
)
5287 enum machine_mode mode
= GET_MODE (x
);
5298 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
5300 return m68hc11_shift_cost (mode
, XEXP (x
, 0), INTVAL (XEXP (x
, 1)));
5303 total
= rtx_cost (XEXP (x
, 0), code
) + rtx_cost (XEXP (x
, 1), code
);
5304 total
+= m68hc11_cost
->shift_var
;
5310 total
= rtx_cost (XEXP (x
, 0), code
) + rtx_cost (XEXP (x
, 1), code
);
5311 total
+= m68hc11_cost
->logical
;
5313 /* Logical instructions are byte instructions only. */
5314 total
*= GET_MODE_SIZE (mode
);
5319 total
= rtx_cost (XEXP (x
, 0), code
) + rtx_cost (XEXP (x
, 1), code
);
5320 total
+= m68hc11_cost
->add
;
5321 if (GET_MODE_SIZE (mode
) > 2)
5323 total
*= GET_MODE_SIZE (mode
) / 2;
5330 total
= rtx_cost (XEXP (x
, 0), code
) + rtx_cost (XEXP (x
, 1), code
);
5334 total
+= m68hc11_cost
->divQI
;
5338 total
+= m68hc11_cost
->divHI
;
5343 total
+= m68hc11_cost
->divSI
;
5349 /* mul instruction produces 16-bit result. */
5350 if (mode
== HImode
&& GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
5351 && GET_CODE (XEXP (x
, 1)) == ZERO_EXTEND
)
5352 return m68hc11_cost
->multQI
5353 + rtx_cost (XEXP (XEXP (x
, 0), 0), code
)
5354 + rtx_cost (XEXP (XEXP (x
, 1), 0), code
);
5356 /* emul instruction produces 32-bit result for 68HC12. */
5357 if (TARGET_M6812
&& mode
== SImode
5358 && GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
5359 && GET_CODE (XEXP (x
, 1)) == ZERO_EXTEND
)
5360 return m68hc11_cost
->multHI
5361 + rtx_cost (XEXP (XEXP (x
, 0), 0), code
)
5362 + rtx_cost (XEXP (XEXP (x
, 1), 0), code
);
5364 total
= rtx_cost (XEXP (x
, 0), code
) + rtx_cost (XEXP (x
, 1), code
);
5368 total
+= m68hc11_cost
->multQI
;
5372 total
+= m68hc11_cost
->multHI
;
5377 total
+= m68hc11_cost
->multSI
;
5384 extra_cost
= COSTS_N_INSNS (2);
5391 total
= extra_cost
+ rtx_cost (XEXP (x
, 0), code
);
5394 return total
+ COSTS_N_INSNS (1);
5398 return total
+ COSTS_N_INSNS (2);
5402 return total
+ COSTS_N_INSNS (4);
5404 return total
+ COSTS_N_INSNS (8);
5407 if (GET_CODE (XEXP (x
, 1)) == PC
|| GET_CODE (XEXP (x
, 2)) == PC
)
5408 return COSTS_N_INSNS (1);
5410 return COSTS_N_INSNS (1);
5413 return COSTS_N_INSNS (4);
5418 m68hc11_rtx_costs (rtx x
, int code
, int outer_code
, int *total
)
5422 /* Constants are cheap. Moving them in registers must be avoided
5423 because most instructions do not handle two register operands. */
5429 /* Logical and arithmetic operations with a constant operand are
5430 better because they are not supported with two registers. */
5432 if (outer_code
== SET
&& x
== const0_rtx
)
5433 /* After reload, the reload_cse pass checks the cost to change
5434 a SET into a PLUS. Make const0 cheap then. */
5435 *total
= 1 - reload_completed
;
5460 *total
= m68hc11_rtx_costs_1 (x
, code
, outer_code
);
5469 /* Worker function for TARGET_ASM_FILE_START. */
5472 m68hc11_file_start (void)
5474 default_file_start ();
5476 fprintf (asm_out_file
, "\t.mode %s\n", TARGET_SHORT
? "mshort" : "mlong");
5480 /* Worker function for TARGET_ASM_CONSTRUCTOR. */
5483 m68hc11_asm_out_constructor (rtx symbol
, int priority
)
5485 default_ctor_section_asm_out_constructor (symbol
, priority
);
5486 fprintf (asm_out_file
, "\t.globl\t__do_global_ctors\n");
5489 /* Worker function for TARGET_ASM_DESTRUCTOR. */
5492 m68hc11_asm_out_destructor (rtx symbol
, int priority
)
5494 default_dtor_section_asm_out_destructor (symbol
, priority
);
5495 fprintf (asm_out_file
, "\t.globl\t__do_global_dtors\n");
5498 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
5501 m68hc11_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
5502 int incoming ATTRIBUTE_UNUSED
)
5504 return gen_rtx_REG (Pmode
, HARD_D_REGNUM
);
5507 /* Return true if type TYPE should be returned in memory.
5508 Blocks and data types largers than 4 bytes cannot be returned
5509 in the register (D + X = 4). */
5512 m68hc11_return_in_memory (tree type
, tree fntype ATTRIBUTE_UNUSED
)
5514 if (TYPE_MODE (type
) == BLKmode
)
5516 HOST_WIDE_INT size
= int_size_in_bytes (type
);
5517 return (size
== -1 || size
> 4);
5520 return GET_MODE_SIZE (TYPE_MODE (type
)) > 4;
5523 #include "gt-m68hc11.h"