1 /* Subroutines for code generation on Motorola 68HC11 and 68HC12.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
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, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, 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 int register_indirect_p (rtx
, enum machine_mode
, int);
69 static rtx
m68hc11_expand_compare (enum rtx_code
, rtx
, rtx
);
70 static int must_parenthesize (rtx
);
71 static int m68hc11_address_cost (rtx
);
72 static int m68hc11_shift_cost (enum machine_mode
, rtx
, int);
73 static int m68hc11_rtx_costs_1 (rtx
, enum rtx_code
, enum rtx_code
);
74 static bool m68hc11_rtx_costs (rtx
, int, int, int *);
75 static int m68hc11_auto_inc_p (rtx
);
76 static tree
m68hc11_handle_fntype_attribute (tree
*, tree
, tree
, int, bool *);
77 const struct attribute_spec m68hc11_attribute_table
[];
79 void create_regs_rtx (void);
81 static void asm_print_register (FILE *, int);
82 static void m68hc11_output_function_epilogue (FILE *, HOST_WIDE_INT
);
83 static void m68hc11_asm_out_constructor (rtx
, int);
84 static void m68hc11_asm_out_destructor (rtx
, int);
85 static void m68hc11_file_start (void);
86 static void m68hc11_encode_section_info (tree
, rtx
, int);
87 static const char *m68hc11_strip_name_encoding (const char* str
);
88 static unsigned int m68hc11_section_type_flags (tree
, const char*, int);
89 static int autoinc_mode (rtx
);
90 static int m68hc11_make_autoinc_notes (rtx
*, void *);
91 static void m68hc11_init_libfuncs (void);
92 static rtx
m68hc11_struct_value_rtx (tree
, int);
93 static bool m68hc11_return_in_memory (tree
, tree
);
95 /* Must be set to 1 to produce debug messages. */
98 extern FILE *asm_out_file
;
103 rtx m68hc11_soft_tmp_reg
;
104 static GTY(()) rtx stack_push_word
;
105 static GTY(()) rtx stack_pop_word
;
106 static GTY(()) rtx z_reg
;
107 static GTY(()) rtx z_reg_qi
;
108 static int regs_inited
= 0;
110 /* Set to 1 by expand_prologue() when the function is an interrupt handler. */
111 int current_function_interrupt
;
113 /* Set to 1 by expand_prologue() when the function is a trap handler. */
114 int current_function_trap
;
116 /* Set to 1 when the current function is placed in 68HC12 banked
117 memory and must return with rtc. */
118 int current_function_far
;
120 /* Min offset that is valid for the indirect addressing mode. */
121 HOST_WIDE_INT m68hc11_min_offset
= 0;
123 /* Max offset that is valid for the indirect addressing mode. */
124 HOST_WIDE_INT m68hc11_max_offset
= 256;
126 /* The class value for base registers. */
127 enum reg_class m68hc11_base_reg_class
= A_REGS
;
129 /* The class value for index registers. This is NO_REGS for 68HC11. */
130 enum reg_class m68hc11_index_reg_class
= NO_REGS
;
132 enum reg_class m68hc11_tmp_regs_class
= NO_REGS
;
134 /* Tables that tell whether a given hard register is valid for
135 a base or an index register. It is filled at init time depending
136 on the target processor. */
137 unsigned char m68hc11_reg_valid_for_base
[FIRST_PSEUDO_REGISTER
];
138 unsigned char m68hc11_reg_valid_for_index
[FIRST_PSEUDO_REGISTER
];
140 /* A correction offset which is applied to the stack pointer.
141 This is 1 for 68HC11 and 0 for 68HC12. */
142 int m68hc11_sp_correction
;
144 #define ADDR_STRICT 0x01 /* Accept only registers in class A_REGS */
145 #define ADDR_INCDEC 0x02 /* Post/Pre inc/dec */
146 #define ADDR_INDEXED 0x04 /* D-reg index */
147 #define ADDR_OFFSET 0x08
148 #define ADDR_INDIRECT 0x10 /* Accept (mem (mem ...)) for [n,X] */
149 #define ADDR_CONST 0x20 /* Accept const and symbol_ref */
151 int m68hc11_addr_mode
;
152 int m68hc11_mov_addr_mode
;
154 /* Comparison operands saved by the "tstxx" and "cmpxx" expand patterns. */
155 rtx m68hc11_compare_op0
;
156 rtx m68hc11_compare_op1
;
159 const struct processor_costs
*m68hc11_cost
;
161 /* Costs for a 68HC11. */
162 static const struct processor_costs m6811_cost
= {
167 /* non-constant shift */
170 { COSTS_N_INSNS (0), COSTS_N_INSNS (1), COSTS_N_INSNS (2),
171 COSTS_N_INSNS (3), COSTS_N_INSNS (4), COSTS_N_INSNS (3),
172 COSTS_N_INSNS (2), COSTS_N_INSNS (1) },
175 { COSTS_N_INSNS (0), COSTS_N_INSNS (1), COSTS_N_INSNS (4),
176 COSTS_N_INSNS (6), COSTS_N_INSNS (8), COSTS_N_INSNS (6),
177 COSTS_N_INSNS (4), COSTS_N_INSNS (2),
178 COSTS_N_INSNS (2), COSTS_N_INSNS (4),
179 COSTS_N_INSNS (6), COSTS_N_INSNS (8), COSTS_N_INSNS (10),
180 COSTS_N_INSNS (8), COSTS_N_INSNS (6), COSTS_N_INSNS (4)
185 COSTS_N_INSNS (20 * 4),
187 COSTS_N_INSNS (20 * 16),
196 /* Costs for a 68HC12. */
197 static const struct processor_costs m6812_cost
= {
202 /* non-constant shift */
205 { COSTS_N_INSNS (0), COSTS_N_INSNS (1), COSTS_N_INSNS (2),
206 COSTS_N_INSNS (3), COSTS_N_INSNS (4), COSTS_N_INSNS (3),
207 COSTS_N_INSNS (2), COSTS_N_INSNS (1) },
210 { COSTS_N_INSNS (0), COSTS_N_INSNS (1), COSTS_N_INSNS (4),
211 COSTS_N_INSNS (6), COSTS_N_INSNS (8), COSTS_N_INSNS (6),
212 COSTS_N_INSNS (4), COSTS_N_INSNS (2),
213 COSTS_N_INSNS (2), COSTS_N_INSNS (4), COSTS_N_INSNS (6),
214 COSTS_N_INSNS (8), COSTS_N_INSNS (10), COSTS_N_INSNS (8),
215 COSTS_N_INSNS (6), COSTS_N_INSNS (4)
222 COSTS_N_INSNS (3 * 4),
231 /* Machine specific options */
233 const char *m68hc11_regparm_string
;
234 const char *m68hc11_reg_alloc_order
;
235 const char *m68hc11_soft_reg_count
;
237 static int nb_soft_regs
;
239 /* Initialize the GCC target structure. */
240 #undef TARGET_ATTRIBUTE_TABLE
241 #define TARGET_ATTRIBUTE_TABLE m68hc11_attribute_table
243 #undef TARGET_ASM_ALIGNED_HI_OP
244 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
246 #undef TARGET_ASM_FUNCTION_EPILOGUE
247 #define TARGET_ASM_FUNCTION_EPILOGUE m68hc11_output_function_epilogue
249 #undef TARGET_ASM_FILE_START
250 #define TARGET_ASM_FILE_START m68hc11_file_start
251 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
252 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
254 #undef TARGET_ENCODE_SECTION_INFO
255 #define TARGET_ENCODE_SECTION_INFO m68hc11_encode_section_info
257 #undef TARGET_SECTION_TYPE_FLAGS
258 #define TARGET_SECTION_TYPE_FLAGS m68hc11_section_type_flags
260 #undef TARGET_RTX_COSTS
261 #define TARGET_RTX_COSTS m68hc11_rtx_costs
262 #undef TARGET_ADDRESS_COST
263 #define TARGET_ADDRESS_COST m68hc11_address_cost
265 #undef TARGET_MACHINE_DEPENDENT_REORG
266 #define TARGET_MACHINE_DEPENDENT_REORG m68hc11_reorg
268 #undef TARGET_INIT_LIBFUNCS
269 #define TARGET_INIT_LIBFUNCS m68hc11_init_libfuncs
271 #undef TARGET_STRUCT_VALUE_RTX
272 #define TARGET_STRUCT_VALUE_RTX m68hc11_struct_value_rtx
273 #undef TARGET_RETURN_IN_MEMORY
274 #define TARGET_RETURN_IN_MEMORY m68hc11_return_in_memory
276 #undef TARGET_STRIP_NAME_ENCODING
277 #define TARGET_STRIP_NAME_ENCODING m68hc11_strip_name_encoding
279 struct gcc_target targetm
= TARGET_INITIALIZER
;
282 m68hc11_override_options (void)
284 memset (m68hc11_reg_valid_for_index
, 0,
285 sizeof (m68hc11_reg_valid_for_index
));
286 memset (m68hc11_reg_valid_for_base
, 0, sizeof (m68hc11_reg_valid_for_base
));
288 /* Compilation with -fpic generates a wrong code. */
291 warning ("-f%s ignored for 68HC11/68HC12 (not supported)",
292 (flag_pic
> 1) ? "PIC" : "pic");
296 /* Configure for a 68hc11 processor. */
299 /* If gcc was built for a 68hc12, invalidate that because
300 a -m68hc11 option was specified on the command line. */
301 if (TARGET_DEFAULT
!= MASK_M6811
)
302 target_flags
&= ~TARGET_DEFAULT
;
305 target_flags
&= ~(TARGET_AUTO_INC_DEC
| TARGET_MIN_MAX
);
306 m68hc11_cost
= &m6811_cost
;
307 m68hc11_min_offset
= 0;
308 m68hc11_max_offset
= 256;
309 m68hc11_index_reg_class
= NO_REGS
;
310 m68hc11_base_reg_class
= A_REGS
;
311 m68hc11_reg_valid_for_base
[HARD_X_REGNUM
] = 1;
312 m68hc11_reg_valid_for_base
[HARD_Y_REGNUM
] = 1;
313 m68hc11_reg_valid_for_base
[HARD_Z_REGNUM
] = 1;
314 m68hc11_sp_correction
= 1;
315 m68hc11_tmp_regs_class
= D_REGS
;
316 m68hc11_addr_mode
= ADDR_OFFSET
;
317 m68hc11_mov_addr_mode
= 0;
318 if (m68hc11_soft_reg_count
== 0 && !TARGET_M6812
)
319 m68hc11_soft_reg_count
= "4";
322 /* Configure for a 68hc12 processor. */
325 m68hc11_cost
= &m6812_cost
;
326 m68hc11_min_offset
= -65536;
327 m68hc11_max_offset
= 65536;
328 m68hc11_index_reg_class
= D_REGS
;
329 m68hc11_base_reg_class
= A_OR_SP_REGS
;
330 m68hc11_reg_valid_for_base
[HARD_X_REGNUM
] = 1;
331 m68hc11_reg_valid_for_base
[HARD_Y_REGNUM
] = 1;
332 m68hc11_reg_valid_for_base
[HARD_Z_REGNUM
] = 1;
333 m68hc11_reg_valid_for_base
[HARD_SP_REGNUM
] = 1;
334 m68hc11_reg_valid_for_index
[HARD_D_REGNUM
] = 1;
335 m68hc11_sp_correction
= 0;
336 m68hc11_tmp_regs_class
= TMP_REGS
;
337 m68hc11_addr_mode
= ADDR_INDIRECT
| ADDR_OFFSET
| ADDR_CONST
338 | (TARGET_AUTO_INC_DEC
? ADDR_INCDEC
: 0);
339 m68hc11_mov_addr_mode
= ADDR_OFFSET
| ADDR_CONST
340 | (TARGET_AUTO_INC_DEC
? ADDR_INCDEC
: 0);
341 target_flags
&= ~MASK_M6811
;
342 target_flags
|= MASK_NO_DIRECT_MODE
;
343 if (m68hc11_soft_reg_count
== 0)
344 m68hc11_soft_reg_count
= "0";
346 if (TARGET_LONG_CALLS
)
347 current_function_far
= 1;
354 m68hc11_conditional_register_usage (void)
357 int cnt
= atoi (m68hc11_soft_reg_count
);
361 if (cnt
> SOFT_REG_LAST
- SOFT_REG_FIRST
)
362 cnt
= SOFT_REG_LAST
- SOFT_REG_FIRST
;
365 for (i
= SOFT_REG_FIRST
+ cnt
; i
< SOFT_REG_LAST
; i
++)
368 call_used_regs
[i
] = 1;
371 /* For 68HC12, the Z register emulation is not necessary when the
372 frame pointer is not used. The frame pointer is eliminated and
373 replaced by the stack register (which is a BASE_REG_CLASS). */
374 if (TARGET_M6812
&& flag_omit_frame_pointer
&& optimize
)
376 fixed_regs
[HARD_Z_REGNUM
] = 1;
381 /* Reload and register operations. */
383 static const char *const reg_class_names
[] = REG_CLASS_NAMES
;
387 create_regs_rtx (void)
389 /* regs_inited = 1; */
390 ix_reg
= gen_rtx_REG (HImode
, HARD_X_REGNUM
);
391 iy_reg
= gen_rtx_REG (HImode
, HARD_Y_REGNUM
);
392 d_reg
= gen_rtx_REG (HImode
, HARD_D_REGNUM
);
393 m68hc11_soft_tmp_reg
= gen_rtx_REG (HImode
, SOFT_TMP_REGNUM
);
395 stack_push_word
= gen_rtx_MEM (HImode
,
396 gen_rtx_PRE_DEC (HImode
,
397 gen_rtx_REG (HImode
, HARD_SP_REGNUM
)));
398 stack_pop_word
= gen_rtx_MEM (HImode
,
399 gen_rtx_POST_INC (HImode
,
400 gen_rtx_REG (HImode
, HARD_SP_REGNUM
)));
404 /* Value is 1 if hard register REGNO can hold a value of machine-mode MODE.
405 - 8 bit values are stored anywhere (except the SP register).
406 - 16 bit values can be stored in any register whose mode is 16
407 - 32 bit values can be stored in D, X registers or in a soft register
408 (except the last one because we need 2 soft registers)
409 - Values whose size is > 32 bit are not stored in real hard
410 registers. They may be stored in soft registers if there are
413 hard_regno_mode_ok (int regno
, enum machine_mode mode
)
415 switch (GET_MODE_SIZE (mode
))
418 return S_REGNO_P (regno
) && nb_soft_regs
>= 4;
421 return X_REGNO_P (regno
) || (S_REGNO_P (regno
) && nb_soft_regs
>= 2);
424 return G_REGNO_P (regno
);
427 /* We have to accept a QImode in X or Y registers. Otherwise, the
428 reload pass will fail when some (SUBREG:QI (REG:HI X)) are defined
429 in the insns. Reload fails if the insn rejects the register class 'a'
430 as well as if it accepts it. Patterns that failed were
431 zero_extend_qihi2 and iorqi3. */
433 return G_REGNO_P (regno
) && !SP_REGNO_P (regno
);
441 m68hc11_hard_regno_rename_ok (int reg1
, int reg2
)
443 /* Don't accept renaming to Z register. We will replace it to
444 X,Y or D during machine reorg pass. */
445 if (reg2
== HARD_Z_REGNUM
)
448 /* Don't accept renaming D,X to Y register as the code will be bigger. */
449 if (TARGET_M6811
&& reg2
== HARD_Y_REGNUM
450 && (D_REGNO_P (reg1
) || X_REGNO_P (reg1
)))
457 preferred_reload_class (rtx operand
, enum reg_class
class)
459 enum machine_mode mode
;
461 mode
= GET_MODE (operand
);
465 printf ("Preferred reload: (class=%s): ", reg_class_names
[class]);
468 if (class == D_OR_A_OR_S_REGS
&& SP_REG_P (operand
))
469 return m68hc11_base_reg_class
;
471 if (class >= S_REGS
&& (GET_CODE (operand
) == MEM
472 || GET_CODE (operand
) == CONST_INT
))
474 /* S_REGS class must not be used. The movhi template does not
475 work to move a memory to a soft register.
476 Restrict to a hard reg. */
481 case D_OR_A_OR_S_REGS
:
487 case D_OR_SP_OR_S_REGS
:
488 class = D_OR_SP_REGS
;
490 case D_OR_Y_OR_S_REGS
:
493 case D_OR_X_OR_S_REGS
:
509 else if (class == Y_REGS
&& GET_CODE (operand
) == MEM
)
513 else if (class == A_OR_D_REGS
&& GET_MODE_SIZE (mode
) == 4)
517 else if (class >= S_REGS
&& S_REG_P (operand
))
523 case D_OR_A_OR_S_REGS
:
529 case D_OR_SP_OR_S_REGS
:
530 class = D_OR_SP_REGS
;
532 case D_OR_Y_OR_S_REGS
:
535 case D_OR_X_OR_S_REGS
:
551 else if (class >= S_REGS
)
555 printf ("Class = %s for: ", reg_class_names
[class]);
563 printf (" => class=%s\n", reg_class_names
[class]);
571 /* Return 1 if the operand is a valid indexed addressing mode.
572 For 68hc11: n,r with n in [0..255] and r in A_REGS class
573 For 68hc12: n,r no constraint on the constant, r in A_REGS class. */
575 register_indirect_p (rtx operand
, enum machine_mode mode
, int addr_mode
)
579 switch (GET_CODE (operand
))
582 if ((addr_mode
& ADDR_INDIRECT
) && GET_MODE_SIZE (mode
) <= 2)
583 return register_indirect_p (XEXP (operand
, 0), mode
,
584 addr_mode
& (ADDR_STRICT
| ADDR_OFFSET
));
591 if (addr_mode
& ADDR_INCDEC
)
592 return register_indirect_p (XEXP (operand
, 0), mode
,
593 addr_mode
& ADDR_STRICT
);
597 base
= XEXP (operand
, 0);
598 if (GET_CODE (base
) == MEM
)
601 offset
= XEXP (operand
, 1);
602 if (GET_CODE (offset
) == MEM
)
605 /* Indexed addressing mode with 2 registers. */
606 if (GET_CODE (base
) == REG
&& GET_CODE (offset
) == REG
)
608 if (!(addr_mode
& ADDR_INDEXED
))
611 addr_mode
&= ADDR_STRICT
;
612 if (REGNO_OK_FOR_BASE_P2 (REGNO (base
), addr_mode
)
613 && REGNO_OK_FOR_INDEX_P2 (REGNO (offset
), addr_mode
))
616 if (REGNO_OK_FOR_BASE_P2 (REGNO (offset
), addr_mode
)
617 && REGNO_OK_FOR_INDEX_P2 (REGNO (base
), addr_mode
))
623 if (!(addr_mode
& ADDR_OFFSET
))
626 if (GET_CODE (base
) == REG
)
628 if (!VALID_CONSTANT_OFFSET_P (offset
, mode
))
631 if (!(addr_mode
& ADDR_STRICT
))
634 return REGNO_OK_FOR_BASE_P2 (REGNO (base
), 1);
637 if (GET_CODE (offset
) == REG
)
639 if (!VALID_CONSTANT_OFFSET_P (base
, mode
))
642 if (!(addr_mode
& ADDR_STRICT
))
645 return REGNO_OK_FOR_BASE_P2 (REGNO (offset
), 1);
650 return REGNO_OK_FOR_BASE_P2 (REGNO (operand
), addr_mode
& ADDR_STRICT
);
653 if (addr_mode
& ADDR_CONST
)
654 return VALID_CONSTANT_OFFSET_P (operand
, mode
);
662 /* Returns 1 if the operand fits in a 68HC11 indirect mode or in
663 a 68HC12 1-byte index addressing mode. */
665 m68hc11_small_indexed_indirect_p (rtx operand
, enum machine_mode mode
)
670 if (GET_CODE (operand
) == REG
&& reload_in_progress
671 && REGNO (operand
) >= FIRST_PSEUDO_REGISTER
672 && reg_equiv_memory_loc
[REGNO (operand
)])
674 operand
= reg_equiv_memory_loc
[REGNO (operand
)];
675 operand
= eliminate_regs (operand
, 0, NULL_RTX
);
678 if (GET_CODE (operand
) != MEM
)
681 operand
= XEXP (operand
, 0);
682 if (CONSTANT_ADDRESS_P (operand
))
685 if (PUSH_POP_ADDRESS_P (operand
))
688 addr_mode
= m68hc11_mov_addr_mode
| (reload_completed
? ADDR_STRICT
: 0);
689 if (!register_indirect_p (operand
, mode
, addr_mode
))
692 if (TARGET_M6812
&& GET_CODE (operand
) == PLUS
693 && (reload_completed
| reload_in_progress
))
695 base
= XEXP (operand
, 0);
696 offset
= XEXP (operand
, 1);
698 /* The offset can be a symbol address and this is too big
699 for the operand constraint. */
700 if (GET_CODE (base
) != CONST_INT
&& GET_CODE (offset
) != CONST_INT
)
703 if (GET_CODE (base
) == CONST_INT
)
706 switch (GET_MODE_SIZE (mode
))
709 if (INTVAL (offset
) < -16 + 6 || INTVAL (offset
) > 15 - 6)
714 if (INTVAL (offset
) < -16 + 2 || INTVAL (offset
) > 15 - 2)
719 if (INTVAL (offset
) < -16 || INTVAL (offset
) > 15)
728 m68hc11_register_indirect_p (rtx operand
, enum machine_mode mode
)
732 if (GET_CODE (operand
) == REG
&& reload_in_progress
733 && REGNO (operand
) >= FIRST_PSEUDO_REGISTER
734 && reg_equiv_memory_loc
[REGNO (operand
)])
736 operand
= reg_equiv_memory_loc
[REGNO (operand
)];
737 operand
= eliminate_regs (operand
, 0, NULL_RTX
);
739 if (GET_CODE (operand
) != MEM
)
742 operand
= XEXP (operand
, 0);
743 addr_mode
= m68hc11_addr_mode
| (reload_completed
? ADDR_STRICT
: 0);
744 return register_indirect_p (operand
, mode
, addr_mode
);
748 go_if_legitimate_address_internal (rtx operand
, enum machine_mode mode
,
753 if (CONSTANT_ADDRESS_P (operand
) && TARGET_M6812
)
755 /* Reject the global variables if they are too wide. This forces
756 a load of their address in a register and generates smaller code. */
757 if (GET_MODE_SIZE (mode
) == 8)
762 addr_mode
= m68hc11_addr_mode
| (strict
? ADDR_STRICT
: 0);
763 if (register_indirect_p (operand
, mode
, addr_mode
))
767 if (PUSH_POP_ADDRESS_P (operand
))
771 if (symbolic_memory_operand (operand
, mode
))
779 m68hc11_go_if_legitimate_address (rtx operand
, enum machine_mode mode
,
786 printf ("Checking: ");
791 result
= go_if_legitimate_address_internal (operand
, mode
, strict
);
795 printf (" -> %s\n", result
== 0 ? "NO" : "YES");
802 printf ("go_if_legitimate%s, ret 0: %d:",
803 (strict
? "_strict" : ""), mode
);
812 m68hc11_legitimize_address (rtx
*operand ATTRIBUTE_UNUSED
,
813 rtx old_operand ATTRIBUTE_UNUSED
,
814 enum machine_mode mode ATTRIBUTE_UNUSED
)
821 m68hc11_reload_operands (rtx operands
[])
823 enum machine_mode mode
;
825 if (regs_inited
== 0)
828 mode
= GET_MODE (operands
[1]);
830 /* Input reload of indirect addressing (MEM (PLUS (REG) (CONST))). */
831 if (A_REG_P (operands
[0]) && memory_reload_operand (operands
[1], mode
))
833 rtx big_offset
= XEXP (XEXP (operands
[1], 0), 1);
834 rtx base
= XEXP (XEXP (operands
[1], 0), 0);
836 if (GET_CODE (base
) != REG
)
843 /* If the offset is out of range, we have to compute the address
844 with a separate add instruction. We try to do with with an 8-bit
845 add on the A register. This is possible only if the lowest part
846 of the offset (ie, big_offset % 256) is a valid constant offset
847 with respect to the mode. If it's not, we have to generate a
848 16-bit add on the D register. From:
850 (SET (REG X (MEM (PLUS (REG X) (CONST_INT 1000)))))
854 [(SET (REG D) (REG X)) (SET (REG X) (REG D))]
855 (SET (REG A) (PLUS (REG A) (CONST_INT 1000 / 256)))
856 [(SET (REG D) (REG X)) (SET (REG X) (REG D))]
857 (SET (REG X) (MEM (PLUS (REG X) (CONST_INT 1000 % 256)))
859 (SET (REG X) (PLUS (REG X) (CONST_INT 1000 / 256 * 256)))
860 (SET (REG X) (MEM (PLUS (REG X) (CONST_INT 1000 % 256))))
863 if (!VALID_CONSTANT_OFFSET_P (big_offset
, mode
))
866 rtx reg
= operands
[0];
868 int val
= INTVAL (big_offset
);
871 /* We use the 'operands[0]' as a scratch register to compute the
872 address. Make sure 'base' is in that register. */
873 if (!rtx_equal_p (base
, operands
[0]))
875 emit_move_insn (reg
, base
);
885 vh
= (val
>> 8) & 0x0FF;
889 /* Create the lowest part offset that still remains to be added.
890 If it's not a valid offset, do a 16-bit add. */
891 offset
= GEN_INT (vl
);
892 if (!VALID_CONSTANT_OFFSET_P (offset
, mode
))
894 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
895 gen_rtx_PLUS (HImode
, reg
, big_offset
)));
900 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
901 gen_rtx_PLUS (HImode
, reg
,
902 GEN_INT (vh
<< 8))));
904 emit_move_insn (operands
[0],
905 gen_rtx_MEM (GET_MODE (operands
[1]),
906 gen_rtx_PLUS (Pmode
, reg
, offset
)));
911 /* Use the normal gen_movhi pattern. */
916 m68hc11_emit_libcall (const char *name
, enum rtx_code code
,
917 enum machine_mode dmode
, enum machine_mode smode
,
918 int noperands
, rtx
*operands
)
926 libcall
= gen_rtx_SYMBOL_REF (Pmode
, name
);
930 ret
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
,
931 dmode
, 1, operands
[1], smode
);
932 equiv
= gen_rtx_fmt_e (code
, dmode
, operands
[1]);
936 ret
= emit_library_call_value (libcall
, NULL_RTX
,
938 operands
[1], smode
, operands
[2],
940 equiv
= gen_rtx_fmt_ee (code
, dmode
, operands
[1], operands
[2]);
947 insns
= get_insns ();
949 emit_libcall_block (insns
, operands
[0], ret
, equiv
);
952 /* Returns true if X is a PRE/POST increment decrement
953 (same as auto_inc_p() in rtlanal.c but do not take into
954 account the stack). */
956 m68hc11_auto_inc_p (rtx x
)
958 return GET_CODE (x
) == PRE_DEC
959 || GET_CODE (x
) == POST_INC
960 || GET_CODE (x
) == POST_DEC
|| GET_CODE (x
) == PRE_INC
;
964 /* Predicates for machine description. */
967 memory_reload_operand (rtx operand
, enum machine_mode mode ATTRIBUTE_UNUSED
)
969 return GET_CODE (operand
) == MEM
970 && GET_CODE (XEXP (operand
, 0)) == PLUS
971 && ((GET_CODE (XEXP (XEXP (operand
, 0), 0)) == REG
972 && GET_CODE (XEXP (XEXP (operand
, 0), 1)) == CONST_INT
)
973 || (GET_CODE (XEXP (XEXP (operand
, 0), 1)) == REG
974 && GET_CODE (XEXP (XEXP (operand
, 0), 0)) == CONST_INT
));
978 tst_operand (rtx operand
, enum machine_mode mode
)
980 if (GET_CODE (operand
) == MEM
&& reload_completed
== 0)
982 rtx addr
= XEXP (operand
, 0);
983 if (m68hc11_auto_inc_p (addr
))
986 return nonimmediate_operand (operand
, mode
);
990 cmp_operand (rtx operand
, enum machine_mode mode
)
992 if (GET_CODE (operand
) == MEM
)
994 rtx addr
= XEXP (operand
, 0);
995 if (m68hc11_auto_inc_p (addr
))
998 return general_operand (operand
, mode
);
1002 non_push_operand (rtx operand
, enum machine_mode mode
)
1004 if (general_operand (operand
, mode
) == 0)
1007 if (push_operand (operand
, mode
) == 1)
1013 splitable_operand (rtx operand
, enum machine_mode mode
)
1015 if (general_operand (operand
, mode
) == 0)
1018 if (push_operand (operand
, mode
) == 1)
1021 /* Reject a (MEM (MEM X)) because the patterns that use non_push_operand
1022 need to split such addresses to access the low and high part but it
1023 is not possible to express a valid address for the low part. */
1024 if (mode
!= QImode
&& GET_CODE (operand
) == MEM
1025 && GET_CODE (XEXP (operand
, 0)) == MEM
)
1031 reg_or_some_mem_operand (rtx operand
, enum machine_mode mode
)
1033 if (GET_CODE (operand
) == MEM
)
1035 rtx op
= XEXP (operand
, 0);
1037 if (symbolic_memory_operand (op
, mode
))
1040 if (IS_STACK_PUSH (operand
))
1043 if (m68hc11_register_indirect_p (operand
, mode
))
1049 return register_operand (operand
, mode
);
1053 m68hc11_symbolic_p (rtx operand
, enum machine_mode mode
)
1055 if (GET_CODE (operand
) == MEM
)
1057 rtx op
= XEXP (operand
, 0);
1059 if (symbolic_memory_operand (op
, mode
))
1066 m68hc11_indirect_p (rtx operand
, enum machine_mode mode
)
1068 if (GET_CODE (operand
) == MEM
&& GET_MODE (operand
) == mode
)
1070 rtx op
= XEXP (operand
, 0);
1073 if (m68hc11_page0_symbol_p (op
))
1076 if (symbolic_memory_operand (op
, mode
))
1077 return TARGET_M6812
;
1079 if (reload_in_progress
)
1082 operand
= XEXP (operand
, 0);
1083 addr_mode
= m68hc11_addr_mode
| (reload_completed
? ADDR_STRICT
: 0);
1084 return register_indirect_p (operand
, mode
, addr_mode
);
1090 stack_register_operand (rtx operand
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1092 return SP_REG_P (operand
);
1096 d_register_operand (rtx operand
, enum machine_mode mode
)
1098 if (GET_MODE (operand
) != mode
&& mode
!= VOIDmode
)
1101 if (GET_CODE (operand
) == SUBREG
)
1102 operand
= XEXP (operand
, 0);
1104 return GET_CODE (operand
) == REG
1105 && (REGNO (operand
) >= FIRST_PSEUDO_REGISTER
1106 || REGNO (operand
) == HARD_D_REGNUM
1107 || (mode
== QImode
&& REGNO (operand
) == HARD_B_REGNUM
));
1111 hard_addr_reg_operand (rtx operand
, enum machine_mode mode
)
1113 if (GET_MODE (operand
) != mode
&& mode
!= VOIDmode
)
1116 if (GET_CODE (operand
) == SUBREG
)
1117 operand
= XEXP (operand
, 0);
1119 return GET_CODE (operand
) == REG
1120 && (REGNO (operand
) == HARD_X_REGNUM
1121 || REGNO (operand
) == HARD_Y_REGNUM
1122 || REGNO (operand
) == HARD_Z_REGNUM
);
1126 hard_reg_operand (rtx operand
, enum machine_mode mode
)
1128 if (GET_MODE (operand
) != mode
&& mode
!= VOIDmode
)
1131 if (GET_CODE (operand
) == SUBREG
)
1132 operand
= XEXP (operand
, 0);
1134 return GET_CODE (operand
) == REG
1135 && (REGNO (operand
) >= FIRST_PSEUDO_REGISTER
1136 || H_REGNO_P (REGNO (operand
)));
1140 memory_indexed_operand (rtx operand
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1142 if (GET_CODE (operand
) != MEM
)
1145 operand
= XEXP (operand
, 0);
1146 if (GET_CODE (operand
) == PLUS
)
1148 if (GET_CODE (XEXP (operand
, 0)) == REG
)
1149 operand
= XEXP (operand
, 0);
1150 else if (GET_CODE (XEXP (operand
, 1)) == REG
)
1151 operand
= XEXP (operand
, 1);
1153 return GET_CODE (operand
) == REG
1154 && (REGNO (operand
) >= FIRST_PSEUDO_REGISTER
1155 || A_REGNO_P (REGNO (operand
)));
1159 push_pop_operand_p (rtx operand
)
1161 if (GET_CODE (operand
) != MEM
)
1165 operand
= XEXP (operand
, 0);
1166 return PUSH_POP_ADDRESS_P (operand
);
1169 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
1170 reference and a constant. */
1173 symbolic_memory_operand (rtx op
, enum machine_mode mode
)
1175 switch (GET_CODE (op
))
1183 return ((GET_CODE (XEXP (op
, 0)) == SYMBOL_REF
1184 || GET_CODE (XEXP (op
, 0)) == LABEL_REF
)
1185 && GET_CODE (XEXP (op
, 1)) == CONST_INT
);
1187 /* ??? This clause seems to be irrelevant. */
1189 return GET_MODE (op
) == mode
;
1192 return symbolic_memory_operand (XEXP (op
, 0), mode
)
1193 && symbolic_memory_operand (XEXP (op
, 1), mode
);
1201 m68hc11_eq_compare_operator (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1203 return GET_CODE (op
) == EQ
|| GET_CODE (op
) == NE
;
1207 m68hc11_logical_operator (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1209 return GET_CODE (op
) == AND
|| GET_CODE (op
) == IOR
|| GET_CODE (op
) == XOR
;
1213 m68hc11_arith_operator (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1215 return GET_CODE (op
) == AND
|| GET_CODE (op
) == IOR
|| GET_CODE (op
) == XOR
1216 || GET_CODE (op
) == PLUS
|| GET_CODE (op
) == MINUS
1217 || GET_CODE (op
) == ASHIFT
|| GET_CODE (op
) == ASHIFTRT
1218 || GET_CODE (op
) == LSHIFTRT
|| GET_CODE (op
) == ROTATE
1219 || GET_CODE (op
) == ROTATERT
;
1223 m68hc11_non_shift_operator (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1225 return GET_CODE (op
) == AND
|| GET_CODE (op
) == IOR
|| GET_CODE (op
) == XOR
1226 || GET_CODE (op
) == PLUS
|| GET_CODE (op
) == MINUS
;
1229 /* Return true if op is a shift operator. */
1231 m68hc11_shift_operator (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1233 return GET_CODE (op
) == ROTATE
|| GET_CODE (op
) == ROTATERT
1234 || GET_CODE (op
) == LSHIFTRT
|| GET_CODE (op
) == ASHIFT
1235 || GET_CODE (op
) == ASHIFTRT
;
1239 m68hc11_unary_operator (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1241 return GET_CODE (op
) == NEG
|| GET_CODE (op
) == NOT
1242 || GET_CODE (op
) == SIGN_EXTEND
|| GET_CODE (op
) == ZERO_EXTEND
;
1245 /* Emit the code to build the trampoline used to call a nested function.
1249 ldy #&CXT movw #&CXT,*_.d1
1250 sty *_.d1 jmp FNADDR
1255 m68hc11_initialize_trampoline (rtx tramp
, rtx fnaddr
, rtx cxt
)
1257 const char *static_chain_reg
= reg_names
[STATIC_CHAIN_REGNUM
];
1260 if (*static_chain_reg
== '*')
1264 emit_move_insn (gen_rtx_MEM (HImode
, tramp
), GEN_INT (0x18ce));
1265 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 2)), cxt
);
1266 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 4)),
1268 emit_move_insn (gen_rtx_MEM (QImode
, plus_constant (tramp
, 6)),
1269 gen_rtx_CONST (QImode
,
1270 gen_rtx_SYMBOL_REF (Pmode
,
1271 static_chain_reg
)));
1272 emit_move_insn (gen_rtx_MEM (QImode
, plus_constant (tramp
, 7)),
1274 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 8)), fnaddr
);
1278 emit_move_insn (gen_rtx_MEM (HImode
, tramp
), GEN_INT (0x1803));
1279 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 2)), cxt
);
1280 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 4)),
1281 gen_rtx_CONST (HImode
,
1282 gen_rtx_SYMBOL_REF (Pmode
,
1283 static_chain_reg
)));
1284 emit_move_insn (gen_rtx_MEM (QImode
, plus_constant (tramp
, 6)),
1286 emit_move_insn (gen_rtx_MEM (HImode
, plus_constant (tramp
, 7)), fnaddr
);
1290 /* Declaration of types. */
1292 /* Handle an "tiny_data" attribute; arguments as in
1293 struct attribute_spec.handler. */
1295 m68hc11_handle_page0_attribute (tree
*node
, tree name
,
1296 tree args ATTRIBUTE_UNUSED
,
1297 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
1301 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
1303 DECL_SECTION_NAME (decl
) = build_string (6, ".page0");
1307 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
1308 *no_add_attrs
= true;
1314 const struct attribute_spec m68hc11_attribute_table
[] =
1316 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
1317 { "interrupt", 0, 0, false, true, true, m68hc11_handle_fntype_attribute
},
1318 { "trap", 0, 0, false, true, true, m68hc11_handle_fntype_attribute
},
1319 { "far", 0, 0, false, true, true, m68hc11_handle_fntype_attribute
},
1320 { "near", 0, 0, false, true, true, m68hc11_handle_fntype_attribute
},
1321 { "page0", 0, 0, false, false, false, m68hc11_handle_page0_attribute
},
1322 { NULL
, 0, 0, false, false, false, NULL
}
1325 /* Keep track of the symbol which has a `trap' attribute and which uses
1326 the `swi' calling convention. Since there is only one trap, we only
1327 record one such symbol. If there are several, a warning is reported. */
1328 static rtx trap_handler_symbol
= 0;
1330 /* Handle an attribute requiring a FUNCTION_TYPE, FIELD_DECL or TYPE_DECL;
1331 arguments as in struct attribute_spec.handler. */
1333 m68hc11_handle_fntype_attribute (tree
*node
, tree name
,
1334 tree args ATTRIBUTE_UNUSED
,
1335 int flags ATTRIBUTE_UNUSED
,
1338 if (TREE_CODE (*node
) != FUNCTION_TYPE
1339 && TREE_CODE (*node
) != METHOD_TYPE
1340 && TREE_CODE (*node
) != FIELD_DECL
1341 && TREE_CODE (*node
) != TYPE_DECL
)
1343 warning ("`%s' attribute only applies to functions",
1344 IDENTIFIER_POINTER (name
));
1345 *no_add_attrs
= true;
1350 /* Undo the effects of the above. */
1353 m68hc11_strip_name_encoding (const char *str
)
1355 return str
+ (*str
== '*' || *str
== '@' || *str
== '&');
1359 m68hc11_encode_label (tree decl
)
1361 const char *str
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1362 int len
= strlen (str
);
1363 char *newstr
= alloca (len
+ 2);
1366 strcpy (&newstr
[1], str
);
1368 XSTR (XEXP (DECL_RTL (decl
), 0), 0) = ggc_alloc_string (newstr
, len
+ 1);
1371 /* Return 1 if this is a symbol in page0 */
1373 m68hc11_page0_symbol_p (rtx x
)
1375 switch (GET_CODE (x
))
1378 return XSTR (x
, 0) != 0 && XSTR (x
, 0)[0] == '@';
1381 return m68hc11_page0_symbol_p (XEXP (x
, 0));
1384 if (!m68hc11_page0_symbol_p (XEXP (x
, 0)))
1387 return GET_CODE (XEXP (x
, 1)) == CONST_INT
1388 && INTVAL (XEXP (x
, 1)) < 256
1389 && INTVAL (XEXP (x
, 1)) >= 0;
1396 /* We want to recognize trap handlers so that we handle calls to traps
1397 in a special manner (by issuing the trap). This information is stored
1398 in SYMBOL_REF_FLAG. */
1401 m68hc11_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
1407 if (TREE_CODE (decl
) == VAR_DECL
)
1409 if (lookup_attribute ("page0", DECL_ATTRIBUTES (decl
)) != 0)
1410 m68hc11_encode_label (decl
);
1414 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1417 func_attr
= TYPE_ATTRIBUTES (TREE_TYPE (decl
));
1420 if (lookup_attribute ("far", func_attr
) != NULL_TREE
)
1422 else if (lookup_attribute ("near", func_attr
) == NULL_TREE
)
1423 is_far
= TARGET_LONG_CALLS
!= 0;
1425 trap_handler
= lookup_attribute ("trap", func_attr
) != NULL_TREE
;
1426 if (trap_handler
&& is_far
)
1428 warning ("`trap' and `far' attributes are not compatible, ignoring `far'");
1433 if (trap_handler_symbol
!= 0)
1434 warning ("`trap' attribute is already used");
1436 trap_handler_symbol
= XEXP (rtl
, 0);
1438 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = is_far
;
1442 m68hc11_section_type_flags (tree decl
, const char *name
, int reloc
)
1444 unsigned int flags
= default_section_type_flags (decl
, name
, reloc
);
1446 if (strncmp (name
, ".eeprom", 7) == 0)
1448 flags
|= SECTION_WRITE
| SECTION_CODE
| SECTION_OVERRIDE
;
1455 m68hc11_is_far_symbol (rtx sym
)
1457 if (GET_CODE (sym
) == MEM
)
1458 sym
= XEXP (sym
, 0);
1460 return SYMBOL_REF_FLAG (sym
);
1464 m68hc11_is_trap_symbol (rtx sym
)
1466 if (GET_CODE (sym
) == MEM
)
1467 sym
= XEXP (sym
, 0);
1469 return trap_handler_symbol
!= 0 && rtx_equal_p (trap_handler_symbol
, sym
);
1473 /* Argument support functions. */
1475 /* Handle the FUNCTION_ARG_PASS_BY_REFERENCE macro.
1476 Arrays are passed by references and other types by value.
1478 SCz: I tried to pass DImode by reference but it seems that this
1479 does not work very well. */
1481 m68hc11_function_arg_pass_by_reference (const CUMULATIVE_ARGS
*cum ATTRIBUTE_UNUSED
,
1482 enum machine_mode mode ATTRIBUTE_UNUSED
,
1484 int named ATTRIBUTE_UNUSED
)
1486 return ((type
&& TREE_CODE (type
) == ARRAY_TYPE
)
1487 /* Consider complex values as aggregates, so care for TCmode. */
1488 /*|| GET_MODE_SIZE (mode) > 4 SCz, temporary */
1489 /*|| (type && AGGREGATE_TYPE_P (type))) */ );
1493 /* Define the offset between two registers, one to be eliminated, and the
1494 other its replacement, at the start of a routine. */
1496 m68hc11_initial_elimination_offset (int from
, int to
)
1503 /* For a trap handler, we must take into account the registers which
1504 are pushed on the stack during the trap (except the PC). */
1505 func_attr
= TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl
));
1506 current_function_interrupt
= lookup_attribute ("interrupt",
1507 func_attr
) != NULL_TREE
;
1508 trap_handler
= lookup_attribute ("trap", func_attr
) != NULL_TREE
;
1510 if (lookup_attribute ("far", func_attr
) != 0)
1511 current_function_far
= 1;
1512 else if (lookup_attribute ("near", func_attr
) != 0)
1513 current_function_far
= 0;
1515 current_function_far
= (TARGET_LONG_CALLS
!= 0
1516 && !current_function_interrupt
1519 if (trap_handler
&& from
== ARG_POINTER_REGNUM
)
1522 /* For a function using 'call/rtc' we must take into account the
1523 page register which is pushed in the call. */
1524 else if (current_function_far
&& from
== ARG_POINTER_REGNUM
)
1529 if (from
== ARG_POINTER_REGNUM
&& to
== HARD_FRAME_POINTER_REGNUM
)
1531 /* 2 is for the saved frame.
1532 1 is for the 'sts' correction when creating the frame. */
1533 return get_frame_size () + 2 + m68hc11_sp_correction
+ size
;
1536 if (from
== FRAME_POINTER_REGNUM
&& to
== HARD_FRAME_POINTER_REGNUM
)
1538 return m68hc11_sp_correction
;
1541 /* Push any 2 byte pseudo hard registers that we need to save. */
1542 for (regno
= SOFT_REG_FIRST
; regno
< SOFT_REG_LAST
; regno
++)
1544 if (regs_ever_live
[regno
] && !call_used_regs
[regno
])
1550 if (from
== ARG_POINTER_REGNUM
&& to
== HARD_SP_REGNUM
)
1552 return get_frame_size () + size
;
1555 if (from
== FRAME_POINTER_REGNUM
&& to
== HARD_SP_REGNUM
)
1562 /* Initialize a variable CUM of type CUMULATIVE_ARGS
1563 for a call to a function whose data type is FNTYPE.
1564 For a library call, FNTYPE is 0. */
1567 m68hc11_init_cumulative_args (CUMULATIVE_ARGS
*cum
, tree fntype
, rtx libname
)
1571 z_replacement_completed
= 0;
1575 /* For a library call, we must find out the type of the return value.
1576 When the return value is bigger than 4 bytes, it is returned in
1577 memory. In that case, the first argument of the library call is a
1578 pointer to the memory location. Because the first argument is passed in
1579 register D, we have to identify this, so that the first function
1580 parameter is not passed in D either. */
1586 if (libname
== 0 || GET_CODE (libname
) != SYMBOL_REF
)
1589 /* If the library ends in 'di' or in 'df', we assume it's
1590 returning some DImode or some DFmode which are 64-bit wide. */
1591 name
= XSTR (libname
, 0);
1592 len
= strlen (name
);
1594 && ((name
[len
- 2] == 'd'
1595 && (name
[len
- 1] == 'f' || name
[len
- 1] == 'i'))
1596 || (name
[len
- 3] == 'd'
1597 && (name
[len
- 2] == 'i' || name
[len
- 2] == 'f'))))
1599 /* We are in. Mark the first parameter register as already used. */
1606 ret_type
= TREE_TYPE (fntype
);
1608 if (ret_type
&& aggregate_value_p (ret_type
, fntype
))
1615 /* Update the data in CUM to advance over an argument
1616 of mode MODE and data type TYPE.
1617 (TYPE is null for libcalls where that information may not be available.) */
1620 m68hc11_function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
1621 tree type
, int named ATTRIBUTE_UNUSED
)
1623 if (mode
!= BLKmode
)
1625 if (cum
->words
== 0 && GET_MODE_SIZE (mode
) == 4)
1628 cum
->words
= GET_MODE_SIZE (mode
);
1632 cum
->words
+= GET_MODE_SIZE (mode
);
1633 if (cum
->words
<= HARD_REG_SIZE
)
1639 cum
->words
+= int_size_in_bytes (type
);
1644 /* Define where to put the arguments to a function.
1645 Value is zero to push the argument on the stack,
1646 or a hard register in which to store the argument.
1648 MODE is the argument's machine mode.
1649 TYPE is the data type of the argument (as a tree).
1650 This is null for libcalls where that information may
1652 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1653 the preceding args and about the function being called.
1654 NAMED is nonzero if this argument is a named parameter
1655 (otherwise it is an extra parameter matching an ellipsis). */
1658 m68hc11_function_arg (const CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
1659 tree type ATTRIBUTE_UNUSED
, int named ATTRIBUTE_UNUSED
)
1661 if (cum
->words
!= 0)
1666 if (mode
!= BLKmode
)
1668 if (GET_MODE_SIZE (mode
) == 2 * HARD_REG_SIZE
)
1669 return gen_rtx_REG (mode
, HARD_X_REGNUM
);
1671 if (GET_MODE_SIZE (mode
) > HARD_REG_SIZE
)
1675 return gen_rtx_REG (mode
, HARD_D_REGNUM
);
1680 /* If defined, a C expression which determines whether, and in which direction,
1681 to pad out an argument with extra space. The value should be of type
1682 `enum direction': either `upward' to pad above the argument,
1683 `downward' to pad below, or `none' to inhibit padding.
1685 Structures are stored left shifted in their argument slot. */
1687 m68hc11_function_arg_padding (enum machine_mode mode
, tree type
)
1689 if (type
!= 0 && AGGREGATE_TYPE_P (type
))
1692 /* Fall back to the default. */
1693 return DEFAULT_FUNCTION_ARG_PADDING (mode
, type
);
1697 /* Function prologue and epilogue. */
1699 /* Emit a move after the reload pass has completed. This is used to
1700 emit the prologue and epilogue. */
1702 emit_move_after_reload (rtx to
, rtx from
, rtx scratch
)
1706 if (TARGET_M6812
|| H_REG_P (to
) || H_REG_P (from
))
1708 insn
= emit_move_insn (to
, from
);
1712 emit_move_insn (scratch
, from
);
1713 insn
= emit_move_insn (to
, scratch
);
1716 /* Put a REG_INC note to tell the flow analysis that the instruction
1718 if (IS_STACK_PUSH (to
))
1720 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_INC
,
1721 XEXP (XEXP (to
, 0), 0),
1724 else if (IS_STACK_POP (from
))
1726 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_INC
,
1727 XEXP (XEXP (from
, 0), 0),
1731 /* For 68HC11, put a REG_INC note on `sts _.frame' to prevent the cse-reg
1732 to think that sp == _.frame and later replace a x = sp with x = _.frame.
1733 The problem is that we are lying to gcc and use `txs' for x = sp
1734 (which is not really true because txs is really x = sp + 1). */
1735 else if (TARGET_M6811
&& SP_REG_P (from
))
1737 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_INC
,
1744 m68hc11_total_frame_size (void)
1749 size
= get_frame_size ();
1750 if (current_function_interrupt
)
1752 size
+= 3 * HARD_REG_SIZE
;
1754 if (frame_pointer_needed
)
1755 size
+= HARD_REG_SIZE
;
1757 for (regno
= SOFT_REG_FIRST
; regno
<= SOFT_REG_LAST
; regno
++)
1758 if (regs_ever_live
[regno
] && !call_used_regs
[regno
])
1759 size
+= HARD_REG_SIZE
;
1765 m68hc11_output_function_epilogue (FILE *out ATTRIBUTE_UNUSED
,
1766 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
1768 /* We catch the function epilogue generation to have a chance
1769 to clear the z_replacement_completed flag. */
1770 z_replacement_completed
= 0;
1774 expand_prologue (void)
1781 if (reload_completed
!= 1)
1784 size
= get_frame_size ();
1788 /* Generate specific prologue for interrupt handlers. */
1789 func_attr
= TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl
));
1790 current_function_interrupt
= lookup_attribute ("interrupt",
1791 func_attr
) != NULL_TREE
;
1792 current_function_trap
= lookup_attribute ("trap", func_attr
) != NULL_TREE
;
1793 if (lookup_attribute ("far", func_attr
) != NULL_TREE
)
1794 current_function_far
= 1;
1795 else if (lookup_attribute ("near", func_attr
) != NULL_TREE
)
1796 current_function_far
= 0;
1798 current_function_far
= (TARGET_LONG_CALLS
!= 0
1799 && !current_function_interrupt
1800 && !current_function_trap
);
1802 /* Get the scratch register to build the frame and push registers.
1803 If the first argument is a 32-bit quantity, the D+X registers
1804 are used. Use Y to compute the frame. Otherwise, X is cheaper.
1805 For 68HC12, this scratch register is not used. */
1806 if (current_function_args_info
.nregs
== 2)
1811 /* Save current stack frame. */
1812 if (frame_pointer_needed
)
1813 emit_move_after_reload (stack_push_word
, hard_frame_pointer_rtx
, scratch
);
1815 /* For an interrupt handler, we must preserve _.tmp, _.z and _.xy.
1816 Other soft registers in page0 need not to be saved because they
1817 will be restored by C functions. For a trap handler, we don't
1818 need to preserve these registers because this is a synchronous call. */
1819 if (current_function_interrupt
)
1821 emit_move_after_reload (stack_push_word
, m68hc11_soft_tmp_reg
, scratch
);
1822 emit_move_after_reload (stack_push_word
,
1823 gen_rtx_REG (HImode
, SOFT_Z_REGNUM
), scratch
);
1824 emit_move_after_reload (stack_push_word
,
1825 gen_rtx_REG (HImode
, SOFT_SAVED_XY_REGNUM
),
1829 /* Allocate local variables. */
1830 if (TARGET_M6812
&& (size
> 4 || size
== 3))
1832 emit_insn (gen_addhi3 (stack_pointer_rtx
,
1833 stack_pointer_rtx
, GEN_INT (-size
)));
1835 else if ((!optimize_size
&& size
> 8) || (optimize_size
&& size
> 10))
1839 insn
= gen_rtx_PARALLEL
1842 gen_rtx_SET (VOIDmode
,
1844 gen_rtx_PLUS (HImode
,
1847 gen_rtx_CLOBBER (VOIDmode
, scratch
)));
1854 /* Allocate by pushing scratch values. */
1855 for (i
= 2; i
<= size
; i
+= 2)
1856 emit_move_after_reload (stack_push_word
, ix_reg
, 0);
1859 emit_insn (gen_addhi3 (stack_pointer_rtx
,
1860 stack_pointer_rtx
, constm1_rtx
));
1863 /* Create the frame pointer. */
1864 if (frame_pointer_needed
)
1865 emit_move_after_reload (hard_frame_pointer_rtx
,
1866 stack_pointer_rtx
, scratch
);
1868 /* Push any 2 byte pseudo hard registers that we need to save. */
1869 for (regno
= SOFT_REG_FIRST
; regno
<= SOFT_REG_LAST
; regno
++)
1871 if (regs_ever_live
[regno
] && !call_used_regs
[regno
])
1873 emit_move_after_reload (stack_push_word
,
1874 gen_rtx_REG (HImode
, regno
), scratch
);
1880 expand_epilogue (void)
1887 if (reload_completed
!= 1)
1890 size
= get_frame_size ();
1892 /* If we are returning a value in two registers, we have to preserve the
1893 X register and use the Y register to restore the stack and the saved
1894 registers. Otherwise, use X because it's faster (and smaller). */
1895 if (current_function_return_rtx
== 0)
1897 else if (GET_CODE (current_function_return_rtx
) == MEM
)
1898 return_size
= HARD_REG_SIZE
;
1900 return_size
= GET_MODE_SIZE (GET_MODE (current_function_return_rtx
));
1902 if (return_size
> HARD_REG_SIZE
&& return_size
<= 2 * HARD_REG_SIZE
)
1907 /* Pop any 2 byte pseudo hard registers that we saved. */
1908 for (regno
= SOFT_REG_LAST
; regno
>= SOFT_REG_FIRST
; regno
--)
1910 if (regs_ever_live
[regno
] && !call_used_regs
[regno
])
1912 emit_move_after_reload (gen_rtx_REG (HImode
, regno
),
1913 stack_pop_word
, scratch
);
1917 /* de-allocate auto variables */
1918 if (TARGET_M6812
&& (size
> 4 || size
== 3))
1920 emit_insn (gen_addhi3 (stack_pointer_rtx
,
1921 stack_pointer_rtx
, GEN_INT (size
)));
1923 else if ((!optimize_size
&& size
> 8) || (optimize_size
&& size
> 10))
1927 insn
= gen_rtx_PARALLEL
1930 gen_rtx_SET (VOIDmode
,
1932 gen_rtx_PLUS (HImode
,
1935 gen_rtx_CLOBBER (VOIDmode
, scratch
)));
1942 for (i
= 2; i
<= size
; i
+= 2)
1943 emit_move_after_reload (scratch
, stack_pop_word
, scratch
);
1945 emit_insn (gen_addhi3 (stack_pointer_rtx
,
1946 stack_pointer_rtx
, const1_rtx
));
1949 /* For an interrupt handler, restore ZTMP, ZREG and XYREG. */
1950 if (current_function_interrupt
)
1952 emit_move_after_reload (gen_rtx_REG (HImode
, SOFT_SAVED_XY_REGNUM
),
1953 stack_pop_word
, scratch
);
1954 emit_move_after_reload (gen_rtx_REG (HImode
, SOFT_Z_REGNUM
),
1955 stack_pop_word
, scratch
);
1956 emit_move_after_reload (m68hc11_soft_tmp_reg
, stack_pop_word
, scratch
);
1959 /* Restore previous frame pointer. */
1960 if (frame_pointer_needed
)
1961 emit_move_after_reload (hard_frame_pointer_rtx
, stack_pop_word
, scratch
);
1963 /* If the trap handler returns some value, copy the value
1964 in D, X onto the stack so that the rti will pop the return value
1966 else if (current_function_trap
&& return_size
!= 0)
1968 rtx addr_reg
= stack_pointer_rtx
;
1972 emit_move_after_reload (scratch
, stack_pointer_rtx
, 0);
1975 emit_move_after_reload (gen_rtx_MEM (HImode
,
1976 gen_rtx_PLUS (HImode
, addr_reg
,
1977 const1_rtx
)), d_reg
, 0);
1978 if (return_size
> HARD_REG_SIZE
)
1979 emit_move_after_reload (gen_rtx_MEM (HImode
,
1980 gen_rtx_PLUS (HImode
, addr_reg
,
1981 GEN_INT (3))), ix_reg
, 0);
1984 emit_jump_insn (gen_return ());
1988 /* Low and High part extraction for 68HC11. These routines are
1989 similar to gen_lowpart and gen_highpart but they have been
1990 fixed to work for constants and 68HC11 specific registers. */
1993 m68hc11_gen_lowpart (enum machine_mode mode
, rtx x
)
1995 /* We assume that the low part of an auto-inc mode is the same with
1996 the mode changed and that the caller split the larger mode in the
1998 if (GET_CODE (x
) == MEM
&& m68hc11_auto_inc_p (XEXP (x
, 0)))
2000 return gen_rtx_MEM (mode
, XEXP (x
, 0));
2003 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
2004 floating-point constant. A CONST_DOUBLE is used whenever the
2005 constant requires more than one word in order to be adequately
2007 if (GET_CODE (x
) == CONST_DOUBLE
)
2011 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
2015 if (GET_MODE (x
) == SFmode
)
2017 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
2018 REAL_VALUE_TO_TARGET_SINGLE (r
, l
[0]);
2024 split_double (x
, &first
, &second
);
2028 return GEN_INT (l
[0]);
2030 return gen_int_mode (l
[0], HImode
);
2034 l
[0] = CONST_DOUBLE_LOW (x
);
2037 return GEN_INT (l
[0]);
2038 else if (mode
== HImode
&& GET_MODE (x
) == SFmode
)
2039 return gen_int_mode (l
[0], HImode
);
2044 if (mode
== QImode
&& D_REG_P (x
))
2045 return gen_rtx_REG (mode
, HARD_B_REGNUM
);
2047 /* gen_lowpart crashes when it is called with a SUBREG. */
2048 if (GET_CODE (x
) == SUBREG
&& SUBREG_BYTE (x
) != 0)
2051 return gen_rtx_SUBREG (mode
, SUBREG_REG (x
), SUBREG_BYTE (x
) + 4);
2052 else if (mode
== HImode
)
2053 return gen_rtx_SUBREG (mode
, SUBREG_REG (x
), SUBREG_BYTE (x
) + 2);
2057 x
= gen_lowpart (mode
, x
);
2059 /* Return a different rtx to avoid to share it in several insns
2060 (when used by a split pattern). Sharing addresses within
2061 a MEM breaks the Z register replacement (and reloading). */
2062 if (GET_CODE (x
) == MEM
)
2068 m68hc11_gen_highpart (enum machine_mode mode
, rtx x
)
2070 /* We assume that the high part of an auto-inc mode is the same with
2071 the mode changed and that the caller split the larger mode in the
2073 if (GET_CODE (x
) == MEM
&& m68hc11_auto_inc_p (XEXP (x
, 0)))
2075 return gen_rtx_MEM (mode
, XEXP (x
, 0));
2078 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
2079 floating-point constant. A CONST_DOUBLE is used whenever the
2080 constant requires more than one word in order to be adequately
2082 if (GET_CODE (x
) == CONST_DOUBLE
)
2086 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
2090 if (GET_MODE (x
) == SFmode
)
2092 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
2093 REAL_VALUE_TO_TARGET_SINGLE (r
, l
[1]);
2099 split_double (x
, &first
, &second
);
2103 return GEN_INT (l
[1]);
2105 return gen_int_mode ((l
[1] >> 16), HImode
);
2109 l
[1] = CONST_DOUBLE_HIGH (x
);
2113 return GEN_INT (l
[1]);
2114 else if (mode
== HImode
&& GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
2115 return gen_int_mode ((l
[0] >> 16), HImode
);
2119 if (GET_CODE (x
) == CONST_INT
)
2121 HOST_WIDE_INT val
= INTVAL (x
);
2125 return gen_int_mode (val
>> 8, QImode
);
2127 else if (mode
== HImode
)
2129 return gen_int_mode (val
>> 16, HImode
);
2132 if (mode
== QImode
&& D_REG_P (x
))
2133 return gen_rtx_REG (mode
, HARD_A_REGNUM
);
2135 /* There is no way in GCC to represent the upper part of a word register.
2136 To obtain the 8-bit upper part of a soft register, we change the
2137 reg into a mem rtx. This is possible because they are physically
2138 located in memory. There is no offset because we are big-endian. */
2139 if (mode
== QImode
&& S_REG_P (x
))
2143 /* Avoid the '*' for direct addressing mode when this
2144 addressing mode is disabled. */
2145 pos
= TARGET_NO_DIRECT_MODE
? 1 : 0;
2146 return gen_rtx_MEM (QImode
,
2147 gen_rtx_SYMBOL_REF (Pmode
,
2148 ®_names
[REGNO (x
)][pos
]));
2151 /* gen_highpart crashes when it is called with a SUBREG. */
2152 if (GET_CODE (x
) == SUBREG
)
2154 return gen_rtx_SUBREG (mode
, XEXP (x
, 0), XEXP (x
, 1));
2156 if (GET_CODE (x
) == REG
)
2158 if (REGNO (x
) < FIRST_PSEUDO_REGISTER
)
2159 return gen_rtx_REG (mode
, REGNO (x
));
2161 return gen_rtx_SUBREG (mode
, x
, 0);
2164 if (GET_CODE (x
) == MEM
)
2166 x
= change_address (x
, mode
, 0);
2168 /* Return a different rtx to avoid to share it in several insns
2169 (when used by a split pattern). Sharing addresses within
2170 a MEM breaks the Z register replacement (and reloading). */
2171 if (GET_CODE (x
) == MEM
)
2179 /* Obscure register manipulation. */
2181 /* Finds backward in the instructions to see if register 'reg' is
2182 dead. This is used when generating code to see if we can use 'reg'
2183 as a scratch register. This allows us to choose a better generation
2184 of code when we know that some register dies or can be clobbered. */
2187 dead_register_here (rtx x
, rtx reg
)
2193 x_reg
= gen_rtx_REG (SImode
, HARD_X_REGNUM
);
2197 for (p
= PREV_INSN (x
); p
&& GET_CODE (p
) != CODE_LABEL
; p
= PREV_INSN (p
))
2204 if (GET_CODE (body
) == CALL_INSN
)
2206 if (GET_CODE (body
) == JUMP_INSN
)
2209 if (GET_CODE (body
) == SET
)
2211 rtx dst
= XEXP (body
, 0);
2213 if (GET_CODE (dst
) == REG
&& REGNO (dst
) == REGNO (reg
))
2215 if (x_reg
&& rtx_equal_p (dst
, x_reg
))
2218 if (find_regno_note (p
, REG_DEAD
, REGNO (reg
)))
2221 else if (reg_mentioned_p (reg
, p
)
2222 || (x_reg
&& reg_mentioned_p (x_reg
, p
)))
2226 /* Scan forward to see if the register is set in some insns and never
2228 for (p
= x
/*NEXT_INSN (x) */ ; p
; p
= NEXT_INSN (p
))
2232 if (GET_CODE (p
) == CODE_LABEL
2233 || GET_CODE (p
) == JUMP_INSN
2234 || GET_CODE (p
) == CALL_INSN
|| GET_CODE (p
) == BARRIER
)
2237 if (GET_CODE (p
) != INSN
)
2241 if (GET_CODE (body
) == SET
)
2243 rtx src
= XEXP (body
, 1);
2244 rtx dst
= XEXP (body
, 0);
2246 if (GET_CODE (dst
) == REG
2247 && REGNO (dst
) == REGNO (reg
) && !reg_mentioned_p (reg
, src
))
2251 /* Register is used (may be in source or in dest). */
2252 if (reg_mentioned_p (reg
, p
)
2253 || (x_reg
!= 0 && GET_MODE (p
) == SImode
2254 && reg_mentioned_p (x_reg
, p
)))
2257 return p
== 0 ? 1 : 0;
2261 /* Code generation operations called from machine description file. */
2263 /* Print the name of register 'regno' in the assembly file. */
2265 asm_print_register (FILE *file
, int regno
)
2267 const char *name
= reg_names
[regno
];
2269 if (TARGET_NO_DIRECT_MODE
&& name
[0] == '*')
2272 fprintf (file
, "%s", name
);
2275 /* A C compound statement to output to stdio stream STREAM the
2276 assembler syntax for an instruction operand X. X is an RTL
2279 CODE is a value that can be used to specify one of several ways
2280 of printing the operand. It is used when identical operands
2281 must be printed differently depending on the context. CODE
2282 comes from the `%' specification that was used to request
2283 printing of the operand. If the specification was just `%DIGIT'
2284 then CODE is 0; if the specification was `%LTR DIGIT' then CODE
2285 is the ASCII code for LTR.
2287 If X is a register, this macro should print the register's name.
2288 The names can be found in an array `reg_names' whose type is
2289 `char *[]'. `reg_names' is initialized from `REGISTER_NAMES'.
2291 When the machine description has a specification `%PUNCT' (a `%'
2292 followed by a punctuation character), this macro is called with
2293 a null pointer for X and the punctuation character for CODE.
2295 The M68HC11 specific codes are:
2297 'b' for the low part of the operand.
2298 'h' for the high part of the operand
2299 The 'b' or 'h' modifiers have no effect if the operand has
2300 the QImode and is not a S_REG_P (soft register). If the
2301 operand is a hard register, these two modifiers have no effect.
2302 't' generate the temporary scratch register. The operand is
2304 'T' generate the low-part temporary scratch register. The operand is
2308 print_operand (FILE *file
, rtx op
, int letter
)
2312 asm_print_register (file
, SOFT_TMP_REGNUM
);
2315 else if (letter
== 'T')
2317 asm_print_register (file
, SOFT_TMP_REGNUM
);
2318 fprintf (file
, "+1");
2321 else if (letter
== '#')
2323 asm_fprintf (file
, "%I");
2326 if (GET_CODE (op
) == REG
)
2328 if (letter
== 'b' && S_REG_P (op
))
2330 asm_print_register (file
, REGNO (op
));
2331 fprintf (file
, "+1");
2333 else if (letter
== 'b' && D_REG_P (op
))
2335 asm_print_register (file
, HARD_B_REGNUM
);
2339 asm_print_register (file
, REGNO (op
));
2344 if (GET_CODE (op
) == SYMBOL_REF
&& (letter
== 'b' || letter
== 'h'))
2347 asm_fprintf (file
, "%I%%lo(");
2349 asm_fprintf (file
, "%I%%hi(");
2351 output_addr_const (file
, op
);
2352 fprintf (file
, ")");
2356 /* Get the low or high part of the operand when 'b' or 'h' modifiers
2357 are specified. If we already have a QImode, there is nothing to do. */
2358 if (GET_MODE (op
) == HImode
|| GET_MODE (op
) == VOIDmode
)
2362 op
= m68hc11_gen_lowpart (QImode
, op
);
2364 else if (letter
== 'h')
2366 op
= m68hc11_gen_highpart (QImode
, op
);
2370 if (GET_CODE (op
) == MEM
)
2372 rtx base
= XEXP (op
, 0);
2373 switch (GET_CODE (base
))
2378 fprintf (file
, "%u,-", GET_MODE_SIZE (GET_MODE (op
)));
2379 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2388 fprintf (file
, "%u,", GET_MODE_SIZE (GET_MODE (op
)));
2389 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2390 fprintf (file
, "-");
2399 fprintf (file
, "%u,", GET_MODE_SIZE (GET_MODE (op
)));
2400 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2401 fprintf (file
, "+");
2410 fprintf (file
, "%u,+", GET_MODE_SIZE (GET_MODE (op
)));
2411 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2420 fprintf (file
, "[");
2421 print_operand_address (file
, XEXP (base
, 0));
2422 fprintf (file
, "]");
2429 if (m68hc11_page0_symbol_p (base
))
2430 fprintf (file
, "*");
2432 output_address (base
);
2436 else if (GET_CODE (op
) == CONST_DOUBLE
&& GET_MODE (op
) == SFmode
)
2441 REAL_VALUE_FROM_CONST_DOUBLE (r
, op
);
2442 REAL_VALUE_TO_TARGET_SINGLE (r
, l
);
2443 asm_fprintf (file
, "%I0x%lx", l
);
2445 else if (GET_CODE (op
) == CONST_DOUBLE
&& GET_MODE (op
) == DFmode
)
2449 real_to_decimal (dstr
, CONST_DOUBLE_REAL_VALUE (op
),
2450 sizeof (dstr
), 0, 1);
2451 asm_fprintf (file
, "%I0r%s", dstr
);
2455 int need_parenthesize
= 0;
2458 asm_fprintf (file
, "%I");
2460 need_parenthesize
= must_parenthesize (op
);
2462 if (need_parenthesize
)
2463 fprintf (file
, "(");
2465 output_addr_const (file
, op
);
2466 if (need_parenthesize
)
2467 fprintf (file
, ")");
2471 /* Returns true if the operand 'op' must be printed with parenthesis
2472 around it. This must be done only if there is a symbol whose name
2473 is a processor register. */
2475 must_parenthesize (rtx op
)
2479 switch (GET_CODE (op
))
2482 name
= XSTR (op
, 0);
2483 /* Avoid a conflict between symbol name and a possible
2485 return (strcasecmp (name
, "a") == 0
2486 || strcasecmp (name
, "b") == 0
2487 || strcasecmp (name
, "d") == 0
2488 || strcasecmp (name
, "x") == 0
2489 || strcasecmp (name
, "y") == 0
2490 || strcasecmp (name
, "ix") == 0
2491 || strcasecmp (name
, "iy") == 0
2492 || strcasecmp (name
, "pc") == 0
2493 || strcasecmp (name
, "sp") == 0
2494 || strcasecmp (name
, "ccr") == 0) ? 1 : 0;
2498 return must_parenthesize (XEXP (op
, 0))
2499 || must_parenthesize (XEXP (op
, 1));
2505 return must_parenthesize (XEXP (op
, 0));
2516 /* A C compound statement to output to stdio stream STREAM the
2517 assembler syntax for an instruction operand that is a memory
2518 reference whose address is ADDR. ADDR is an RTL expression. */
2521 print_operand_address (FILE *file
, rtx addr
)
2525 int need_parenthesis
= 0;
2527 switch (GET_CODE (addr
))
2530 if (!REG_P (addr
) || !REG_OK_FOR_BASE_STRICT_P (addr
))
2533 fprintf (file
, "0,");
2534 asm_print_register (file
, REGNO (addr
));
2538 base
= XEXP (addr
, 0);
2539 switch (GET_CODE (base
))
2544 fprintf (file
, "%u,-", GET_MODE_SIZE (GET_MODE (addr
)));
2545 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2554 fprintf (file
, "%u,", GET_MODE_SIZE (GET_MODE (addr
)));
2555 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2556 fprintf (file
, "-");
2565 fprintf (file
, "%u,", GET_MODE_SIZE (GET_MODE (addr
)));
2566 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2567 fprintf (file
, "+");
2576 fprintf (file
, "%u,+", GET_MODE_SIZE (GET_MODE (addr
)));
2577 asm_print_register (file
, REGNO (XEXP (base
, 0)));
2584 need_parenthesis
= must_parenthesize (base
);
2585 if (need_parenthesis
)
2586 fprintf (file
, "(");
2588 output_addr_const (file
, base
);
2589 if (need_parenthesis
)
2590 fprintf (file
, ")");
2596 base
= XEXP (addr
, 0);
2597 offset
= XEXP (addr
, 1);
2598 if (!G_REG_P (base
) && G_REG_P (offset
))
2600 base
= XEXP (addr
, 1);
2601 offset
= XEXP (addr
, 0);
2603 if ((CONSTANT_ADDRESS_P (base
)) && (CONSTANT_ADDRESS_P (offset
)))
2605 need_parenthesis
= must_parenthesize (addr
);
2607 if (need_parenthesis
)
2608 fprintf (file
, "(");
2610 output_addr_const (file
, base
);
2611 fprintf (file
, "+");
2612 output_addr_const (file
, offset
);
2613 if (need_parenthesis
)
2614 fprintf (file
, ")");
2616 else if (REG_P (base
) && REG_OK_FOR_BASE_STRICT_P (base
))
2622 asm_print_register (file
, REGNO (offset
));
2623 fprintf (file
, ",");
2624 asm_print_register (file
, REGNO (base
));
2631 need_parenthesis
= must_parenthesize (offset
);
2632 if (need_parenthesis
)
2633 fprintf (file
, "(");
2635 output_addr_const (file
, offset
);
2636 if (need_parenthesis
)
2637 fprintf (file
, ")");
2638 fprintf (file
, ",");
2639 asm_print_register (file
, REGNO (base
));
2649 if (GET_CODE (addr
) == CONST_INT
2650 && INTVAL (addr
) < 0x8000 && INTVAL (addr
) >= -0x8000)
2652 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (addr
));
2656 need_parenthesis
= must_parenthesize (addr
);
2657 if (need_parenthesis
)
2658 fprintf (file
, "(");
2660 output_addr_const (file
, addr
);
2661 if (need_parenthesis
)
2662 fprintf (file
, ")");
2669 /* Splitting of some instructions. */
2672 m68hc11_expand_compare (enum rtx_code code
, rtx op0
, rtx op1
)
2676 if (GET_MODE_CLASS (GET_MODE (op0
)) == MODE_FLOAT
)
2680 emit_insn (gen_rtx_SET (VOIDmode
, cc0_rtx
,
2681 gen_rtx_COMPARE (VOIDmode
, op0
, op1
)));
2682 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, cc0_rtx
, const0_rtx
);
2689 m68hc11_expand_compare_and_branch (enum rtx_code code
, rtx op0
, rtx op1
,
2694 switch (GET_MODE (op0
))
2698 tmp
= m68hc11_expand_compare (code
, op0
, op1
);
2699 tmp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, tmp
,
2700 gen_rtx_LABEL_REF (VOIDmode
, label
),
2702 emit_jump_insn (gen_rtx_SET (VOIDmode
, pc_rtx
, tmp
));
2706 /* SCz: from i386.c */
2709 /* Don't expand the comparison early, so that we get better code
2710 when jump or whoever decides to reverse the comparison. */
2715 code
= m68hc11_prepare_fp_compare_args (code
, &m68hc11_compare_op0
,
2716 &m68hc11_compare_op1
);
2718 tmp
= gen_rtx_fmt_ee (code
, m68hc11_fp_compare_mode (code
),
2719 m68hc11_compare_op0
, m68hc11_compare_op1
);
2720 tmp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, tmp
,
2721 gen_rtx_LABEL_REF (VOIDmode
, label
),
2723 tmp
= gen_rtx_SET (VOIDmode
, pc_rtx
, tmp
);
2725 use_fcomi
= ix86_use_fcomi_compare (code
);
2726 vec
= rtvec_alloc (3 + !use_fcomi
);
2727 RTVEC_ELT (vec
, 0) = tmp
;
2729 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCFPmode
, 18));
2731 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCFPmode
, 17));
2734 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_SCRATCH (HImode
));
2736 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, vec
));
2742 /* Expand SImode branch into multiple compare+branch. */
2744 rtx lo
[2], hi
[2], label2
;
2745 enum rtx_code code1
, code2
, code3
;
2747 if (CONSTANT_P (op0
) && !CONSTANT_P (op1
))
2752 code
= swap_condition (code
);
2754 lo
[0] = m68hc11_gen_lowpart (HImode
, op0
);
2755 lo
[1] = m68hc11_gen_lowpart (HImode
, op1
);
2756 hi
[0] = m68hc11_gen_highpart (HImode
, op0
);
2757 hi
[1] = m68hc11_gen_highpart (HImode
, op1
);
2759 /* Otherwise, if we are doing less-than, op1 is a constant and the
2760 low word is zero, then we can just examine the high word. */
2762 if (GET_CODE (hi
[1]) == CONST_INT
&& lo
[1] == const0_rtx
2763 && (code
== LT
|| code
== LTU
))
2765 return m68hc11_expand_compare_and_branch (code
, hi
[0], hi
[1],
2769 /* Otherwise, we need two or three jumps. */
2771 label2
= gen_label_rtx ();
2774 code2
= swap_condition (code
);
2775 code3
= unsigned_condition (code
);
2816 * if (hi(a) < hi(b)) goto true;
2817 * if (hi(a) > hi(b)) goto false;
2818 * if (lo(a) < lo(b)) goto true;
2822 m68hc11_expand_compare_and_branch (code1
, hi
[0], hi
[1], label
);
2824 m68hc11_expand_compare_and_branch (code2
, hi
[0], hi
[1], label2
);
2826 m68hc11_expand_compare_and_branch (code3
, lo
[0], lo
[1], label
);
2829 emit_label (label2
);
2839 /* Return the increment/decrement mode of a MEM if it is such.
2840 Return CONST if it is anything else. */
2842 autoinc_mode (rtx x
)
2844 if (GET_CODE (x
) != MEM
)
2848 if (GET_CODE (x
) == PRE_INC
2849 || GET_CODE (x
) == PRE_DEC
2850 || GET_CODE (x
) == POST_INC
2851 || GET_CODE (x
) == POST_DEC
)
2852 return GET_CODE (x
);
2858 m68hc11_make_autoinc_notes (rtx
*x
, void *data
)
2862 switch (GET_CODE (*x
))
2869 REG_NOTES (insn
) = alloc_EXPR_LIST (REG_INC
, XEXP (*x
, 0),
2878 /* Split a DI, SI or HI move into several smaller move operations.
2879 The scratch register 'scratch' is used as a temporary to load
2880 store intermediate values. It must be a hard register. */
2882 m68hc11_split_move (rtx to
, rtx from
, rtx scratch
)
2884 rtx low_to
, low_from
;
2885 rtx high_to
, high_from
;
2887 enum machine_mode mode
;
2889 int autoinc_from
= autoinc_mode (from
);
2890 int autoinc_to
= autoinc_mode (to
);
2892 mode
= GET_MODE (to
);
2894 /* If the TO and FROM contain autoinc modes that are not compatible
2895 together (one pop and the other a push), we must change one to
2896 an offsetable operand and generate an appropriate add at the end. */
2897 if (TARGET_M6812
&& GET_MODE_SIZE (mode
) > 2)
2902 /* The source uses an autoinc mode which is not compatible with
2903 a split (this would result in a word swap). */
2904 if (autoinc_from
== PRE_INC
|| autoinc_from
== POST_DEC
)
2906 code
= GET_CODE (XEXP (from
, 0));
2907 reg
= XEXP (XEXP (from
, 0), 0);
2908 offset
= GET_MODE_SIZE (GET_MODE (from
));
2909 if (code
== POST_DEC
)
2912 if (code
== PRE_INC
)
2913 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2915 m68hc11_split_move (to
, gen_rtx_MEM (GET_MODE (from
), reg
), scratch
);
2916 if (code
== POST_DEC
)
2917 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2921 /* Likewise for destination. */
2922 if (autoinc_to
== PRE_INC
|| autoinc_to
== POST_DEC
)
2924 code
= GET_CODE (XEXP (to
, 0));
2925 reg
= XEXP (XEXP (to
, 0), 0);
2926 offset
= GET_MODE_SIZE (GET_MODE (to
));
2927 if (code
== POST_DEC
)
2930 if (code
== PRE_INC
)
2931 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2933 m68hc11_split_move (gen_rtx_MEM (GET_MODE (to
), reg
), from
, scratch
);
2934 if (code
== POST_DEC
)
2935 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2939 /* The source and destination auto increment modes must be compatible
2940 with each other: same direction. */
2941 if ((autoinc_to
!= autoinc_from
2942 && autoinc_to
!= CONST
&& autoinc_from
!= CONST
)
2943 /* The destination address register must not be used within
2944 the source operand because the source address would change
2945 while doing the copy. */
2946 || (autoinc_to
!= CONST
2947 && reg_mentioned_p (XEXP (XEXP (to
, 0), 0), from
)
2948 && !IS_STACK_PUSH (to
)))
2950 /* Must change the destination. */
2951 code
= GET_CODE (XEXP (to
, 0));
2952 reg
= XEXP (XEXP (to
, 0), 0);
2953 offset
= GET_MODE_SIZE (GET_MODE (to
));
2954 if (code
== PRE_DEC
|| code
== POST_DEC
)
2957 if (code
== PRE_DEC
|| code
== PRE_INC
)
2958 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2959 m68hc11_split_move (gen_rtx_MEM (GET_MODE (to
), reg
), from
, scratch
);
2960 if (code
== POST_DEC
|| code
== POST_INC
)
2961 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2966 /* Likewise, the source address register must not be used within
2967 the destination operand. */
2968 if (autoinc_from
!= CONST
2969 && reg_mentioned_p (XEXP (XEXP (from
, 0), 0), to
)
2970 && !IS_STACK_PUSH (to
))
2972 /* Must change the source. */
2973 code
= GET_CODE (XEXP (from
, 0));
2974 reg
= XEXP (XEXP (from
, 0), 0);
2975 offset
= GET_MODE_SIZE (GET_MODE (from
));
2976 if (code
== PRE_DEC
|| code
== POST_DEC
)
2979 if (code
== PRE_DEC
|| code
== PRE_INC
)
2980 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2981 m68hc11_split_move (to
, gen_rtx_MEM (GET_MODE (from
), reg
), scratch
);
2982 if (code
== POST_DEC
|| code
== POST_INC
)
2983 emit_insn (gen_addhi3 (reg
, reg
, GEN_INT (offset
)));
2989 if (GET_MODE_SIZE (mode
) == 8)
2991 else if (GET_MODE_SIZE (mode
) == 4)
2997 && IS_STACK_PUSH (to
)
2998 && reg_mentioned_p (gen_rtx_REG (HImode
, HARD_SP_REGNUM
), from
))
3004 else if (mode
== HImode
)
3012 low_to
= m68hc11_gen_lowpart (mode
, to
);
3013 high_to
= m68hc11_gen_highpart (mode
, to
);
3015 low_from
= m68hc11_gen_lowpart (mode
, from
);
3016 if (mode
== SImode
&& GET_CODE (from
) == CONST_INT
)
3018 if (INTVAL (from
) >= 0)
3019 high_from
= const0_rtx
;
3021 high_from
= constm1_rtx
;
3024 high_from
= m68hc11_gen_highpart (mode
, from
);
3028 high_from
= adjust_address (high_from
, mode
, offset
);
3029 low_from
= high_from
;
3032 /* When copying with a POST_INC mode, we must copy the
3033 high part and then the low part to guarantee a correct
3036 && GET_MODE_SIZE (mode
) >= 2
3037 && autoinc_from
!= autoinc_to
3038 && (autoinc_from
== POST_INC
|| autoinc_to
== POST_INC
))
3047 low_from
= high_from
;
3052 m68hc11_split_move (low_to
, low_from
, scratch
);
3053 m68hc11_split_move (high_to
, high_from
, scratch
);
3055 else if (H_REG_P (to
) || H_REG_P (from
)
3056 || (low_from
== const0_rtx
3057 && high_from
== const0_rtx
3058 && ! push_operand (to
, GET_MODE (to
))
3059 && ! H_REG_P (scratch
))
3061 && (!m68hc11_register_indirect_p (from
, GET_MODE (from
))
3062 || m68hc11_small_indexed_indirect_p (from
,
3064 && (!m68hc11_register_indirect_p (to
, GET_MODE (to
))
3065 || m68hc11_small_indexed_indirect_p (to
, GET_MODE (to
)))))
3067 insn
= emit_move_insn (low_to
, low_from
);
3068 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
3070 insn
= emit_move_insn (high_to
, high_from
);
3071 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
3075 insn
= emit_move_insn (scratch
, low_from
);
3076 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
3077 insn
= emit_move_insn (low_to
, scratch
);
3078 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
3080 insn
= emit_move_insn (scratch
, high_from
);
3081 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
3082 insn
= emit_move_insn (high_to
, scratch
);
3083 for_each_rtx (&PATTERN (insn
), m68hc11_make_autoinc_notes
, insn
);
3088 simplify_logical (enum machine_mode mode
, int code
, rtx operand
, rtx
*result
)
3094 if (GET_CODE (operand
) != CONST_INT
)
3102 val
= INTVAL (operand
);
3106 if ((val
& mask
) == 0)
3108 if ((val
& mask
) == mask
)
3109 *result
= constm1_rtx
;
3113 if ((val
& mask
) == 0)
3114 *result
= const0_rtx
;
3115 if ((val
& mask
) == mask
)
3120 if ((val
& mask
) == 0)
3128 m68hc11_emit_logical (enum machine_mode mode
, int code
, rtx
*operands
)
3133 need_copy
= (rtx_equal_p (operands
[0], operands
[1])
3134 || rtx_equal_p (operands
[0], operands
[2])) ? 0 : 1;
3136 operands
[1] = simplify_logical (mode
, code
, operands
[1], &result
);
3137 operands
[2] = simplify_logical (mode
, code
, operands
[2], &result
);
3139 if (result
&& GET_CODE (result
) == CONST_INT
)
3141 if (!H_REG_P (operands
[0]) && operands
[3]
3142 && (INTVAL (result
) != 0 || IS_STACK_PUSH (operands
[0])))
3144 emit_move_insn (operands
[3], result
);
3145 emit_move_insn (operands
[0], operands
[3]);
3149 emit_move_insn (operands
[0], result
);
3152 else if (operands
[1] != 0 && operands
[2] != 0)
3156 if (!H_REG_P (operands
[0]) && operands
[3])
3158 emit_move_insn (operands
[3], operands
[1]);
3159 emit_insn (gen_rtx_SET (mode
,
3161 gen_rtx_fmt_ee (code
, mode
,
3162 operands
[3], operands
[2])));
3163 insn
= emit_move_insn (operands
[0], operands
[3]);
3167 insn
= emit_insn (gen_rtx_SET (mode
,
3169 gen_rtx_fmt_ee (code
, mode
,
3175 /* The logical operation is similar to a copy. */
3180 if (GET_CODE (operands
[1]) == CONST_INT
)
3185 if (!H_REG_P (operands
[0]) && !H_REG_P (src
))
3187 emit_move_insn (operands
[3], src
);
3188 emit_move_insn (operands
[0], operands
[3]);
3192 emit_move_insn (operands
[0], src
);
3198 m68hc11_split_logical (enum machine_mode mode
, int code
, rtx
*operands
)
3203 low
[0] = m68hc11_gen_lowpart (mode
, operands
[0]);
3204 low
[1] = m68hc11_gen_lowpart (mode
, operands
[1]);
3205 low
[2] = m68hc11_gen_lowpart (mode
, operands
[2]);
3207 high
[0] = m68hc11_gen_highpart (mode
, operands
[0]);
3209 if (mode
== SImode
&& GET_CODE (operands
[1]) == CONST_INT
)
3211 if (INTVAL (operands
[1]) >= 0)
3212 high
[1] = const0_rtx
;
3214 high
[1] = constm1_rtx
;
3217 high
[1] = m68hc11_gen_highpart (mode
, operands
[1]);
3219 if (mode
== SImode
&& GET_CODE (operands
[2]) == CONST_INT
)
3221 if (INTVAL (operands
[2]) >= 0)
3222 high
[2] = const0_rtx
;
3224 high
[2] = constm1_rtx
;
3227 high
[2] = m68hc11_gen_highpart (mode
, operands
[2]);
3229 low
[3] = operands
[3];
3230 high
[3] = operands
[3];
3233 m68hc11_split_logical (HImode
, code
, low
);
3234 m68hc11_split_logical (HImode
, code
, high
);
3238 m68hc11_emit_logical (mode
, code
, low
);
3239 m68hc11_emit_logical (mode
, code
, high
);
3243 /* Code generation. */
3246 m68hc11_output_swap (rtx insn ATTRIBUTE_UNUSED
, rtx operands
[])
3248 /* We have to be careful with the cc_status. An address register swap
3249 is generated for some comparison. The comparison is made with D
3250 but the branch really uses the address register. See the split
3251 pattern for compare. The xgdx/xgdy preserve the flags but after
3252 the exchange, the flags will reflect to the value of X and not D.
3253 Tell this by setting the cc_status according to the cc_prev_status. */
3254 if (X_REG_P (operands
[1]) || X_REG_P (operands
[0]))
3256 if (cc_prev_status
.value1
!= 0
3257 && (D_REG_P (cc_prev_status
.value1
)
3258 || X_REG_P (cc_prev_status
.value1
)))
3260 cc_status
= cc_prev_status
;
3261 if (D_REG_P (cc_status
.value1
))
3262 cc_status
.value1
= gen_rtx_REG (GET_MODE (cc_status
.value1
),
3265 cc_status
.value1
= gen_rtx_REG (GET_MODE (cc_status
.value1
),
3271 output_asm_insn ("xgdx", operands
);
3275 if (cc_prev_status
.value1
!= 0
3276 && (D_REG_P (cc_prev_status
.value1
)
3277 || Y_REG_P (cc_prev_status
.value1
)))
3279 cc_status
= cc_prev_status
;
3280 if (D_REG_P (cc_status
.value1
))
3281 cc_status
.value1
= gen_rtx_REG (GET_MODE (cc_status
.value1
),
3284 cc_status
.value1
= gen_rtx_REG (GET_MODE (cc_status
.value1
),
3290 output_asm_insn ("xgdy", operands
);
3294 /* Returns 1 if the next insn after 'insn' is a test of the register 'reg'.
3295 This is used to decide whether a move that set flags should be used
3298 next_insn_test_reg (rtx insn
, rtx reg
)
3302 insn
= next_nonnote_insn (insn
);
3303 if (GET_CODE (insn
) != INSN
)
3306 body
= PATTERN (insn
);
3307 if (sets_cc0_p (body
) != 1)
3310 if (rtx_equal_p (XEXP (body
, 1), reg
) == 0)
3316 /* Generate the code to move a 16-bit operand into another one. */
3319 m68hc11_gen_movhi (rtx insn
, rtx
*operands
)
3323 /* Move a register or memory to the same location.
3324 This is possible because such insn can appear
3325 in a non-optimizing mode. */
3326 if (operands
[0] == operands
[1] || rtx_equal_p (operands
[0], operands
[1]))
3328 cc_status
= cc_prev_status
;
3334 if (IS_STACK_PUSH (operands
[0]) && H_REG_P (operands
[1]))
3336 cc_status
= cc_prev_status
;
3337 switch (REGNO (operands
[1]))
3342 output_asm_insn ("psh%1", operands
);
3344 case HARD_SP_REGNUM
:
3345 output_asm_insn ("sts\t2,-sp", operands
);
3352 if (IS_STACK_POP (operands
[1]) && H_REG_P (operands
[0]))
3354 cc_status
= cc_prev_status
;
3355 switch (REGNO (operands
[0]))
3360 output_asm_insn ("pul%0", operands
);
3367 if (H_REG_P (operands
[0]) && H_REG_P (operands
[1]))
3369 m68hc11_notice_keep_cc (operands
[0]);
3370 output_asm_insn ("tfr\t%1,%0", operands
);
3372 else if (H_REG_P (operands
[0]))
3374 if (SP_REG_P (operands
[0]))
3375 output_asm_insn ("lds\t%1", operands
);
3377 output_asm_insn ("ld%0\t%1", operands
);
3379 else if (H_REG_P (operands
[1]))
3381 if (SP_REG_P (operands
[1]))
3382 output_asm_insn ("sts\t%0", operands
);
3384 output_asm_insn ("st%1\t%0", operands
);
3388 rtx from
= operands
[1];
3389 rtx to
= operands
[0];
3391 if ((m68hc11_register_indirect_p (from
, GET_MODE (from
))
3392 && !m68hc11_small_indexed_indirect_p (from
, GET_MODE (from
)))
3393 || (m68hc11_register_indirect_p (to
, GET_MODE (to
))
3394 && !m68hc11_small_indexed_indirect_p (to
, GET_MODE (to
))))
3400 ops
[0] = operands
[2];
3403 m68hc11_gen_movhi (insn
, ops
);
3405 ops
[1] = operands
[2];
3406 m68hc11_gen_movhi (insn
, ops
);
3410 /* !!!! SCz wrong here. */
3411 fatal_insn ("move insn not handled", insn
);
3416 if (GET_CODE (from
) == CONST_INT
&& INTVAL (from
) == 0)
3418 output_asm_insn ("clr\t%h0", operands
);
3419 output_asm_insn ("clr\t%b0", operands
);
3423 m68hc11_notice_keep_cc (operands
[0]);
3424 output_asm_insn ("movw\t%1,%0", operands
);
3431 if (IS_STACK_POP (operands
[1]) && H_REG_P (operands
[0]))
3433 cc_status
= cc_prev_status
;
3434 switch (REGNO (operands
[0]))
3438 output_asm_insn ("pul%0", operands
);
3441 output_asm_insn ("pula", operands
);
3442 output_asm_insn ("pulb", operands
);
3449 /* Some moves to a hard register are special. Not all of them
3450 are really supported and we have to use a temporary
3451 location to provide them (either the stack of a temp var). */
3452 if (H_REG_P (operands
[0]))
3454 switch (REGNO (operands
[0]))
3457 if (X_REG_P (operands
[1]))
3459 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_X_REGNUM
))
3461 m68hc11_output_swap (insn
, operands
);
3463 else if (next_insn_test_reg (insn
, operands
[0]))
3465 output_asm_insn ("stx\t%t0\n\tldd\t%t0", operands
);
3469 m68hc11_notice_keep_cc (operands
[0]);
3470 output_asm_insn ("pshx\n\tpula\n\tpulb", operands
);
3473 else if (Y_REG_P (operands
[1]))
3475 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_Y_REGNUM
))
3477 m68hc11_output_swap (insn
, operands
);
3481 /* %t means *ZTMP scratch register. */
3482 output_asm_insn ("sty\t%t1", operands
);
3483 output_asm_insn ("ldd\t%t1", operands
);
3486 else if (SP_REG_P (operands
[1]))
3491 if (optimize
== 0 || dead_register_here (insn
, ix_reg
) == 0)
3492 output_asm_insn ("xgdx", operands
);
3493 output_asm_insn ("tsx", operands
);
3494 output_asm_insn ("xgdx", operands
);
3496 else if (IS_STACK_POP (operands
[1]))
3498 output_asm_insn ("pula\n\tpulb", operands
);
3500 else if (GET_CODE (operands
[1]) == CONST_INT
3501 && INTVAL (operands
[1]) == 0)
3503 output_asm_insn ("clra\n\tclrb", operands
);
3507 output_asm_insn ("ldd\t%1", operands
);
3512 if (D_REG_P (operands
[1]))
3514 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_D_REGNUM
))
3516 m68hc11_output_swap (insn
, operands
);
3518 else if (next_insn_test_reg (insn
, operands
[0]))
3520 output_asm_insn ("std\t%t0\n\tldx\t%t0", operands
);
3524 m68hc11_notice_keep_cc (operands
[0]);
3525 output_asm_insn ("pshb", operands
);
3526 output_asm_insn ("psha", operands
);
3527 output_asm_insn ("pulx", operands
);
3530 else if (Y_REG_P (operands
[1]))
3532 /* When both D and Y are dead, use the sequence xgdy, xgdx
3533 to move Y into X. The D and Y registers are modified. */
3534 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_Y_REGNUM
)
3535 && dead_register_here (insn
, d_reg
))
3537 output_asm_insn ("xgdy", operands
);
3538 output_asm_insn ("xgdx", operands
);
3541 else if (!optimize_size
)
3543 output_asm_insn ("sty\t%t1", operands
);
3544 output_asm_insn ("ldx\t%t1", operands
);
3549 output_asm_insn ("pshy", operands
);
3550 output_asm_insn ("pulx", operands
);
3553 else if (SP_REG_P (operands
[1]))
3555 /* tsx, tsy preserve the flags */
3556 cc_status
= cc_prev_status
;
3557 output_asm_insn ("tsx", operands
);
3561 output_asm_insn ("ldx\t%1", operands
);
3566 if (D_REG_P (operands
[1]))
3568 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_D_REGNUM
))
3570 m68hc11_output_swap (insn
, operands
);
3574 output_asm_insn ("std\t%t1", operands
);
3575 output_asm_insn ("ldy\t%t1", operands
);
3578 else if (X_REG_P (operands
[1]))
3580 /* When both D and X are dead, use the sequence xgdx, xgdy
3581 to move X into Y. The D and X registers are modified. */
3582 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_X_REGNUM
)
3583 && dead_register_here (insn
, d_reg
))
3585 output_asm_insn ("xgdx", operands
);
3586 output_asm_insn ("xgdy", operands
);
3589 else if (!optimize_size
)
3591 output_asm_insn ("stx\t%t1", operands
);
3592 output_asm_insn ("ldy\t%t1", operands
);
3597 output_asm_insn ("pshx", operands
);
3598 output_asm_insn ("puly", operands
);
3601 else if (SP_REG_P (operands
[1]))
3603 /* tsx, tsy preserve the flags */
3604 cc_status
= cc_prev_status
;
3605 output_asm_insn ("tsy", operands
);
3609 output_asm_insn ("ldy\t%1", operands
);
3613 case HARD_SP_REGNUM
:
3614 if (D_REG_P (operands
[1]))
3616 m68hc11_notice_keep_cc (operands
[0]);
3617 output_asm_insn ("xgdx", operands
);
3618 output_asm_insn ("txs", operands
);
3619 output_asm_insn ("xgdx", operands
);
3621 else if (X_REG_P (operands
[1]))
3623 /* tys, txs preserve the flags */
3624 cc_status
= cc_prev_status
;
3625 output_asm_insn ("txs", operands
);
3627 else if (Y_REG_P (operands
[1]))
3629 /* tys, txs preserve the flags */
3630 cc_status
= cc_prev_status
;
3631 output_asm_insn ("tys", operands
);
3635 /* lds sets the flags but the des does not. */
3637 output_asm_insn ("lds\t%1", operands
);
3638 output_asm_insn ("des", operands
);
3643 fatal_insn ("invalid register in the move instruction", insn
);
3648 if (SP_REG_P (operands
[1]) && REG_P (operands
[0])
3649 && REGNO (operands
[0]) == HARD_FRAME_POINTER_REGNUM
)
3651 output_asm_insn ("sts\t%0", operands
);
3655 if (IS_STACK_PUSH (operands
[0]) && H_REG_P (operands
[1]))
3657 cc_status
= cc_prev_status
;
3658 switch (REGNO (operands
[1]))
3662 output_asm_insn ("psh%1", operands
);
3665 output_asm_insn ("pshb", operands
);
3666 output_asm_insn ("psha", operands
);
3674 /* Operand 1 must be a hard register. */
3675 if (!H_REG_P (operands
[1]))
3677 fatal_insn ("invalid operand in the instruction", insn
);
3680 reg
= REGNO (operands
[1]);
3684 output_asm_insn ("std\t%0", operands
);
3688 output_asm_insn ("stx\t%0", operands
);
3692 output_asm_insn ("sty\t%0", operands
);
3695 case HARD_SP_REGNUM
:
3699 if (REG_P (operands
[0]) && REGNO (operands
[0]) == SOFT_TMP_REGNUM
)
3701 output_asm_insn ("pshx", operands
);
3702 output_asm_insn ("tsx", operands
);
3703 output_asm_insn ("inx", operands
);
3704 output_asm_insn ("inx", operands
);
3705 output_asm_insn ("stx\t%0", operands
);
3706 output_asm_insn ("pulx", operands
);
3709 else if (reg_mentioned_p (ix_reg
, operands
[0]))
3711 output_asm_insn ("sty\t%t0", operands
);
3712 output_asm_insn ("tsy", operands
);
3713 output_asm_insn ("sty\t%0", operands
);
3714 output_asm_insn ("ldy\t%t0", operands
);
3718 output_asm_insn ("stx\t%t0", operands
);
3719 output_asm_insn ("tsx", operands
);
3720 output_asm_insn ("stx\t%0", operands
);
3721 output_asm_insn ("ldx\t%t0", operands
);
3727 fatal_insn ("invalid register in the move instruction", insn
);
3733 m68hc11_gen_movqi (rtx insn
, rtx
*operands
)
3735 /* Move a register or memory to the same location.
3736 This is possible because such insn can appear
3737 in a non-optimizing mode. */
3738 if (operands
[0] == operands
[1] || rtx_equal_p (operands
[0], operands
[1]))
3740 cc_status
= cc_prev_status
;
3747 if (H_REG_P (operands
[0]) && H_REG_P (operands
[1]))
3749 m68hc11_notice_keep_cc (operands
[0]);
3750 output_asm_insn ("tfr\t%1,%0", operands
);
3752 else if (H_REG_P (operands
[0]))
3754 if (Q_REG_P (operands
[0]))
3755 output_asm_insn ("lda%0\t%b1", operands
);
3756 else if (D_REG_P (operands
[0]))
3757 output_asm_insn ("ldab\t%b1", operands
);
3761 else if (H_REG_P (operands
[1]))
3763 if (Q_REG_P (operands
[1]))
3764 output_asm_insn ("sta%1\t%b0", operands
);
3765 else if (D_REG_P (operands
[1]))
3766 output_asm_insn ("stab\t%b0", operands
);
3772 rtx from
= operands
[1];
3773 rtx to
= operands
[0];
3775 if ((m68hc11_register_indirect_p (from
, GET_MODE (from
))
3776 && !m68hc11_small_indexed_indirect_p (from
, GET_MODE (from
)))
3777 || (m68hc11_register_indirect_p (to
, GET_MODE (to
))
3778 && !m68hc11_small_indexed_indirect_p (to
, GET_MODE (to
))))
3784 ops
[0] = operands
[2];
3787 m68hc11_gen_movqi (insn
, ops
);
3789 ops
[1] = operands
[2];
3790 m68hc11_gen_movqi (insn
, ops
);
3794 /* !!!! SCz wrong here. */
3795 fatal_insn ("move insn not handled", insn
);
3800 if (GET_CODE (from
) == CONST_INT
&& INTVAL (from
) == 0)
3802 output_asm_insn ("clr\t%b0", operands
);
3806 m68hc11_notice_keep_cc (operands
[0]);
3807 output_asm_insn ("movb\t%b1,%b0", operands
);
3815 if (H_REG_P (operands
[0]))
3817 switch (REGNO (operands
[0]))
3821 if (X_REG_P (operands
[1]))
3823 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_X_REGNUM
))
3825 m68hc11_output_swap (insn
, operands
);
3829 output_asm_insn ("stx\t%t1", operands
);
3830 output_asm_insn ("ldab\t%T0", operands
);
3833 else if (Y_REG_P (operands
[1]))
3835 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_Y_REGNUM
))
3837 m68hc11_output_swap (insn
, operands
);
3841 output_asm_insn ("sty\t%t1", operands
);
3842 output_asm_insn ("ldab\t%T0", operands
);
3845 else if (!DB_REG_P (operands
[1]) && !D_REG_P (operands
[1])
3846 && !DA_REG_P (operands
[1]))
3848 output_asm_insn ("ldab\t%b1", operands
);
3850 else if (DA_REG_P (operands
[1]))
3852 output_asm_insn ("tab", operands
);
3856 cc_status
= cc_prev_status
;
3862 if (X_REG_P (operands
[1]))
3864 output_asm_insn ("stx\t%t1", operands
);
3865 output_asm_insn ("ldaa\t%T0", operands
);
3867 else if (Y_REG_P (operands
[1]))
3869 output_asm_insn ("sty\t%t1", operands
);
3870 output_asm_insn ("ldaa\t%T0", operands
);
3872 else if (!DB_REG_P (operands
[1]) && !D_REG_P (operands
[1])
3873 && !DA_REG_P (operands
[1]))
3875 output_asm_insn ("ldaa\t%b1", operands
);
3877 else if (!DA_REG_P (operands
[1]))
3879 output_asm_insn ("tba", operands
);
3883 cc_status
= cc_prev_status
;
3888 if (D_REG_P (operands
[1]))
3890 if (optimize
&& find_regno_note (insn
, REG_DEAD
, HARD_D_REGNUM
))
3892 m68hc11_output_swap (insn
, operands
);
3896 output_asm_insn ("stab\t%T1", operands
);
3897 output_asm_insn ("ldx\t%t1", operands
);
3901 else if (Y_REG_P (operands
[1]))
3903 output_asm_insn ("sty\t%t0", operands
);
3904 output_asm_insn ("ldx\t%t0", operands
);
3906 else if (GET_CODE (operands
[1]) == CONST_INT
)
3908 output_asm_insn ("ldx\t%1", operands
);
3910 else if (dead_register_here (insn
, d_reg
))
3912 output_asm_insn ("ldab\t%b1", operands
);
3913 output_asm_insn ("xgdx", operands
);
3915 else if (!reg_mentioned_p (operands
[0], operands
[1]))
3917 output_asm_insn ("xgdx", operands
);
3918 output_asm_insn ("ldab\t%b1", operands
);
3919 output_asm_insn ("xgdx", operands
);
3923 output_asm_insn ("pshb", operands
);
3924 output_asm_insn ("ldab\t%b1", operands
);
3925 output_asm_insn ("stab\t%T1", operands
);
3926 output_asm_insn ("ldx\t%t1", operands
);
3927 output_asm_insn ("pulb", operands
);
3933 if (D_REG_P (operands
[1]))
3935 output_asm_insn ("stab\t%T1", operands
);
3936 output_asm_insn ("ldy\t%t1", operands
);
3939 else if (X_REG_P (operands
[1]))
3941 output_asm_insn ("stx\t%t1", operands
);
3942 output_asm_insn ("ldy\t%t1", operands
);
3945 else if (GET_CODE (operands
[1]) == CONST_INT
)
3947 output_asm_insn ("ldy\t%1", operands
);
3949 else if (dead_register_here (insn
, d_reg
))
3951 output_asm_insn ("ldab\t%b1", operands
);
3952 output_asm_insn ("xgdy", operands
);
3954 else if (!reg_mentioned_p (operands
[0], operands
[1]))
3956 output_asm_insn ("xgdy", operands
);
3957 output_asm_insn ("ldab\t%b1", operands
);
3958 output_asm_insn ("xgdy", operands
);
3962 output_asm_insn ("pshb", operands
);
3963 output_asm_insn ("ldab\t%b1", operands
);
3964 output_asm_insn ("stab\t%T1", operands
);
3965 output_asm_insn ("ldy\t%t1", operands
);
3966 output_asm_insn ("pulb", operands
);
3972 fatal_insn ("invalid register in the instruction", insn
);
3976 else if (H_REG_P (operands
[1]))
3978 switch (REGNO (operands
[1]))
3982 output_asm_insn ("stab\t%b0", operands
);
3986 output_asm_insn ("staa\t%b0", operands
);
3990 output_asm_insn ("xgdx\n\tstab\t%b0\n\txgdx", operands
);
3994 output_asm_insn ("xgdy\n\tstab\t%b0\n\txgdy", operands
);
3998 fatal_insn ("invalid register in the move instruction", insn
);
4005 fatal_insn ("operand 1 must be a hard register", insn
);
4009 /* Generate the code for a ROTATE or ROTATERT on a QI or HI mode.
4010 The source and destination must be D or A and the shift must
4013 m68hc11_gen_rotate (enum rtx_code code
, rtx insn
, rtx operands
[])
4017 if (GET_CODE (operands
[2]) != CONST_INT
4018 || (!D_REG_P (operands
[0]) && !DA_REG_P (operands
[0])))
4019 fatal_insn ("invalid rotate insn", insn
);
4021 val
= INTVAL (operands
[2]);
4022 if (code
== ROTATERT
)
4023 val
= GET_MODE_SIZE (GET_MODE (operands
[0])) * BITS_PER_UNIT
- val
;
4025 if (GET_MODE (operands
[0]) != QImode
)
4028 /* Rotate by 8-bits if the shift is within [5..11]. */
4029 if (val
>= 5 && val
<= 11)
4032 output_asm_insn ("exg\ta,b", operands
);
4035 output_asm_insn ("psha", operands
);
4036 output_asm_insn ("tba", operands
);
4037 output_asm_insn ("pulb", operands
);
4042 /* If the shift is big, invert the rotation. */
4052 /* Set the carry to bit-15, but don't change D yet. */
4053 if (GET_MODE (operands
[0]) != QImode
)
4055 output_asm_insn ("asra", operands
);
4056 output_asm_insn ("rola", operands
);
4059 /* Rotate B first to move the carry to bit-0. */
4060 if (D_REG_P (operands
[0]))
4061 output_asm_insn ("rolb", operands
);
4063 if (GET_MODE (operands
[0]) != QImode
|| DA_REG_P (operands
[0]))
4064 output_asm_insn ("rola", operands
);
4071 /* Set the carry to bit-8 of D. */
4072 if (GET_MODE (operands
[0]) != QImode
)
4073 output_asm_insn ("tap", operands
);
4075 /* Rotate B first to move the carry to bit-7. */
4076 if (D_REG_P (operands
[0]))
4077 output_asm_insn ("rorb", operands
);
4079 if (GET_MODE (operands
[0]) != QImode
|| DA_REG_P (operands
[0]))
4080 output_asm_insn ("rora", operands
);
4087 /* Store in cc_status the expressions that the condition codes will
4088 describe after execution of an instruction whose pattern is EXP.
4089 Do not alter them if the instruction would not alter the cc's. */
4092 m68hc11_notice_update_cc (rtx exp
, rtx insn ATTRIBUTE_UNUSED
)
4094 /* recognize SET insn's. */
4095 if (GET_CODE (exp
) == SET
)
4097 /* Jumps do not alter the cc's. */
4098 if (SET_DEST (exp
) == pc_rtx
)
4101 /* NOTE: most instructions don't affect the carry bit, but the
4102 bhi/bls/bhs/blo instructions use it. This isn't mentioned in
4103 the conditions.h header. */
4105 /* Function calls clobber the cc's. */
4106 else if (GET_CODE (SET_SRC (exp
)) == CALL
)
4111 /* Tests and compares set the cc's in predictable ways. */
4112 else if (SET_DEST (exp
) == cc0_rtx
)
4114 cc_status
.flags
= 0;
4115 cc_status
.value1
= XEXP (exp
, 0);
4116 cc_status
.value2
= XEXP (exp
, 1);
4120 /* All other instructions affect the condition codes. */
4121 cc_status
.flags
= 0;
4122 cc_status
.value1
= XEXP (exp
, 0);
4123 cc_status
.value2
= XEXP (exp
, 1);
4128 /* Default action if we haven't recognized something
4129 and returned earlier. */
4133 if (cc_status
.value2
!= 0)
4134 switch (GET_CODE (cc_status
.value2
))
4136 /* These logical operations can generate several insns.
4137 The flags are setup according to what is generated. */
4143 /* The (not ...) generates several 'com' instructions for
4144 non QImode. We have to invalidate the flags. */
4146 if (GET_MODE (cc_status
.value2
) != QImode
)
4158 if (GET_MODE (cc_status
.value2
) != VOIDmode
)
4159 cc_status
.flags
|= CC_NO_OVERFLOW
;
4162 /* The asl sets the overflow bit in such a way that this
4163 makes the flags unusable for a next compare insn. */
4167 if (GET_MODE (cc_status
.value2
) != VOIDmode
)
4168 cc_status
.flags
|= CC_NO_OVERFLOW
;
4171 /* A load/store instruction does not affect the carry. */
4176 cc_status
.flags
|= CC_NO_OVERFLOW
;
4182 if (cc_status
.value1
&& GET_CODE (cc_status
.value1
) == REG
4184 && reg_overlap_mentioned_p (cc_status
.value1
, cc_status
.value2
))
4185 cc_status
.value2
= 0;
4187 else if (cc_status
.value1
&& side_effects_p (cc_status
.value1
))
4188 cc_status
.value1
= 0;
4190 else if (cc_status
.value2
&& side_effects_p (cc_status
.value2
))
4191 cc_status
.value2
= 0;
4194 /* The current instruction does not affect the flags but changes
4195 the register 'reg'. See if the previous flags can be kept for the
4196 next instruction to avoid a comparison. */
4198 m68hc11_notice_keep_cc (rtx reg
)
4201 || cc_prev_status
.value1
== 0
4202 || rtx_equal_p (reg
, cc_prev_status
.value1
)
4203 || (cc_prev_status
.value2
4204 && reg_mentioned_p (reg
, cc_prev_status
.value2
)))
4207 cc_status
= cc_prev_status
;
4212 /* Machine Specific Reorg. */
4214 /* Z register replacement:
4216 GCC treats the Z register as an index base address register like
4217 X or Y. In general, it uses it during reload to compute the address
4218 of some operand. This helps the reload pass to avoid to fall into the
4219 register spill failure.
4221 The Z register is in the A_REGS class. In the machine description,
4222 the 'A' constraint matches it. The 'x' or 'y' constraints do not.
4224 It can appear everywhere an X or Y register can appear, except for
4225 some templates in the clobber section (when a clobber of X or Y is asked).
4226 For a given instruction, the template must ensure that no more than
4227 2 'A' registers are used. Otherwise, the register replacement is not
4230 To replace the Z register, the algorithm is not terrific:
4231 1. Insns that do not use the Z register are not changed
4232 2. When a Z register is used, we scan forward the insns to see
4233 a potential register to use: either X or Y and sometimes D.
4234 We stop when a call, a label or a branch is seen, or when we
4235 detect that both X and Y are used (probably at different times, but it does
4237 3. The register that will be used for the replacement of Z is saved
4238 in a .page0 register or on the stack. If the first instruction that
4239 used Z, uses Z as an input, the value is loaded from another .page0
4240 register. The replacement register is pushed on the stack in the
4241 rare cases where a compare insn uses Z and we couldn't find if X/Y
4243 4. The Z register is replaced in all instructions until we reach
4244 the end of the Z-block, as detected by step 2.
4245 5. If we detect that Z is still alive, its value is saved.
4246 If the replacement register is alive, its old value is loaded.
4248 The Z register can be disabled with -ffixed-z.
4258 int must_restore_reg
;
4269 int save_before_last
;
4270 int z_loaded_with_sp
;
4273 static int m68hc11_check_z_replacement (rtx
, struct replace_info
*);
4274 static void m68hc11_find_z_replacement (rtx
, struct replace_info
*);
4275 static void m68hc11_z_replacement (rtx
);
4276 static void m68hc11_reassign_regs (rtx
);
4278 int z_replacement_completed
= 0;
4280 /* Analyze the insn to find out which replacement register to use and
4281 the boundaries of the replacement.
4282 Returns 0 if we reached the last insn to be replaced, 1 if we can
4283 continue replacement in next insns. */
4286 m68hc11_check_z_replacement (rtx insn
, struct replace_info
*info
)
4288 int this_insn_uses_ix
;
4289 int this_insn_uses_iy
;
4290 int this_insn_uses_z
;
4291 int this_insn_uses_z_in_dst
;
4292 int this_insn_uses_d
;
4296 /* A call is said to clobber the Z register, we don't need
4297 to save the value of Z. We also don't need to restore
4298 the replacement register (unless it is used by the call). */
4299 if (GET_CODE (insn
) == CALL_INSN
)
4301 body
= PATTERN (insn
);
4303 info
->can_use_d
= 0;
4305 /* If the call is an indirect call with Z, we have to use the
4306 Y register because X can be used as an input (D+X).
4307 We also must not save Z nor restore Y. */
4308 if (reg_mentioned_p (z_reg
, body
))
4310 insn
= NEXT_INSN (insn
);
4313 info
->found_call
= 1;
4314 info
->must_restore_reg
= 0;
4315 info
->last
= NEXT_INSN (insn
);
4317 info
->need_save_z
= 0;
4320 if (GET_CODE (insn
) == CODE_LABEL
4321 || GET_CODE (insn
) == BARRIER
|| GET_CODE (insn
) == ASM_INPUT
)
4324 if (GET_CODE (insn
) == JUMP_INSN
)
4326 if (reg_mentioned_p (z_reg
, insn
) == 0)
4329 info
->can_use_d
= 0;
4330 info
->must_save_reg
= 0;
4331 info
->must_restore_reg
= 0;
4332 info
->need_save_z
= 0;
4333 info
->last
= NEXT_INSN (insn
);
4336 if (GET_CODE (insn
) != INSN
&& GET_CODE (insn
) != JUMP_INSN
)
4341 /* Z register dies here. */
4342 z_dies_here
= find_regno_note (insn
, REG_DEAD
, HARD_Z_REGNUM
) != NULL
;
4344 body
= PATTERN (insn
);
4345 if (GET_CODE (body
) == SET
)
4347 rtx src
= XEXP (body
, 1);
4348 rtx dst
= XEXP (body
, 0);
4350 /* Condition code is set here. We have to restore the X/Y and
4351 save into Z before any test/compare insn because once we save/restore
4352 we can change the condition codes. When the compare insn uses Z and
4353 we can't use X/Y, the comparison is made with the *ZREG soft register
4354 (this is supported by cmphi, cmpqi, tsthi, tstqi patterns). */
4357 if ((GET_CODE (src
) == REG
&& REGNO (src
) == HARD_Z_REGNUM
)
4358 || (GET_CODE (src
) == COMPARE
&&
4359 ((rtx_equal_p (XEXP (src
, 0), z_reg
)
4360 && H_REG_P (XEXP (src
, 1)))
4361 || (rtx_equal_p (XEXP (src
, 1), z_reg
)
4362 && H_REG_P (XEXP (src
, 0))))))
4364 if (insn
== info
->first
)
4366 info
->must_load_z
= 0;
4367 info
->must_save_reg
= 0;
4368 info
->must_restore_reg
= 0;
4369 info
->need_save_z
= 0;
4370 info
->found_call
= 1;
4371 info
->regno
= SOFT_Z_REGNUM
;
4372 info
->last
= NEXT_INSN (insn
);
4376 if (reg_mentioned_p (z_reg
, src
) == 0)
4378 info
->can_use_d
= 0;
4382 if (insn
!= info
->first
)
4385 /* Compare insn which uses Z. We have to save/restore the X/Y
4386 register without modifying the condition codes. For this
4387 we have to use a push/pop insn. */
4388 info
->must_push_reg
= 1;
4392 /* Z reg is set to something new. We don't need to load it. */
4395 if (!reg_mentioned_p (z_reg
, src
))
4397 /* Z reg is used before being set. Treat this as
4398 a new sequence of Z register replacement. */
4399 if (insn
!= info
->first
)
4403 info
->must_load_z
= 0;
4405 info
->z_set_count
++;
4406 info
->z_value
= src
;
4408 info
->z_loaded_with_sp
= 1;
4410 else if (reg_mentioned_p (z_reg
, dst
))
4411 info
->can_use_d
= 0;
4413 this_insn_uses_d
= reg_mentioned_p (d_reg
, src
)
4414 | reg_mentioned_p (d_reg
, dst
);
4415 this_insn_uses_ix
= reg_mentioned_p (ix_reg
, src
)
4416 | reg_mentioned_p (ix_reg
, dst
);
4417 this_insn_uses_iy
= reg_mentioned_p (iy_reg
, src
)
4418 | reg_mentioned_p (iy_reg
, dst
);
4419 this_insn_uses_z
= reg_mentioned_p (z_reg
, src
);
4421 /* If z is used as an address operand (like (MEM (reg z))),
4422 we can't replace it with d. */
4423 if (this_insn_uses_z
&& !Z_REG_P (src
)
4424 && !(m68hc11_arith_operator (src
, GET_MODE (src
))
4425 && Z_REG_P (XEXP (src
, 0))
4426 && !reg_mentioned_p (z_reg
, XEXP (src
, 1))
4427 && insn
== info
->first
4428 && dead_register_here (insn
, d_reg
)))
4429 info
->can_use_d
= 0;
4431 this_insn_uses_z_in_dst
= reg_mentioned_p (z_reg
, dst
);
4432 if (TARGET_M6812
&& !z_dies_here
4433 && ((this_insn_uses_z
&& side_effects_p (src
))
4434 || (this_insn_uses_z_in_dst
&& side_effects_p (dst
))))
4436 info
->need_save_z
= 1;
4437 info
->z_set_count
++;
4439 this_insn_uses_z
|= this_insn_uses_z_in_dst
;
4441 if (this_insn_uses_z
&& this_insn_uses_ix
&& this_insn_uses_iy
)
4443 fatal_insn ("registers IX, IY and Z used in the same INSN", insn
);
4446 if (this_insn_uses_d
)
4447 info
->can_use_d
= 0;
4449 /* IX and IY are used at the same time, we have to restore
4450 the value of the scratch register before this insn. */
4451 if (this_insn_uses_ix
&& this_insn_uses_iy
)
4456 if (this_insn_uses_ix
&& X_REG_P (dst
) && GET_MODE (dst
) == SImode
)
4457 info
->can_use_d
= 0;
4459 if (info
->x_used
== 0 && this_insn_uses_ix
)
4463 /* We have a (set (REG:HI X) (REG:HI Z)).
4464 Since we use Z as the replacement register, this insn
4465 is no longer necessary. We turn it into a note. We must
4466 not reload the old value of X. */
4467 if (X_REG_P (dst
) && rtx_equal_p (src
, z_reg
))
4471 info
->need_save_z
= 0;
4474 info
->must_save_reg
= 0;
4475 info
->must_restore_reg
= 0;
4476 info
->found_call
= 1;
4477 info
->can_use_d
= 0;
4478 PUT_CODE (insn
, NOTE
);
4479 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
4480 NOTE_SOURCE_FILE (insn
) = 0;
4481 info
->last
= NEXT_INSN (insn
);
4486 && (rtx_equal_p (src
, z_reg
)
4487 || (z_dies_here
&& !reg_mentioned_p (ix_reg
, src
))))
4491 info
->need_save_z
= 0;
4494 info
->last
= NEXT_INSN (insn
);
4495 info
->must_save_reg
= 0;
4496 info
->must_restore_reg
= 0;
4498 else if (X_REG_P (dst
) && reg_mentioned_p (z_reg
, src
)
4499 && !reg_mentioned_p (ix_reg
, src
))
4504 info
->need_save_z
= 0;
4506 else if (TARGET_M6812
&& side_effects_p (src
))
4509 info
->must_restore_reg
= 0;
4514 info
->save_before_last
= 1;
4516 info
->must_restore_reg
= 0;
4517 info
->last
= NEXT_INSN (insn
);
4519 else if (info
->can_use_d
)
4521 info
->last
= NEXT_INSN (insn
);
4527 if (z_dies_here
&& !reg_mentioned_p (ix_reg
, src
)
4528 && GET_CODE (dst
) == REG
&& REGNO (dst
) == HARD_X_REGNUM
)
4530 info
->need_save_z
= 0;
4532 info
->last
= NEXT_INSN (insn
);
4533 info
->regno
= HARD_X_REGNUM
;
4534 info
->must_save_reg
= 0;
4535 info
->must_restore_reg
= 0;
4538 if (rtx_equal_p (src
, z_reg
) && rtx_equal_p (dst
, ix_reg
))
4540 info
->regno
= HARD_X_REGNUM
;
4541 info
->must_restore_reg
= 0;
4542 info
->must_save_reg
= 0;
4546 if (info
->y_used
== 0 && this_insn_uses_iy
)
4550 if (Y_REG_P (dst
) && rtx_equal_p (src
, z_reg
))
4554 info
->need_save_z
= 0;
4557 info
->must_save_reg
= 0;
4558 info
->must_restore_reg
= 0;
4559 info
->found_call
= 1;
4560 info
->can_use_d
= 0;
4561 PUT_CODE (insn
, NOTE
);
4562 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
4563 NOTE_SOURCE_FILE (insn
) = 0;
4564 info
->last
= NEXT_INSN (insn
);
4569 && (rtx_equal_p (src
, z_reg
)
4570 || (z_dies_here
&& !reg_mentioned_p (iy_reg
, src
))))
4575 info
->need_save_z
= 0;
4577 info
->last
= NEXT_INSN (insn
);
4578 info
->must_save_reg
= 0;
4579 info
->must_restore_reg
= 0;
4581 else if (Y_REG_P (dst
) && reg_mentioned_p (z_reg
, src
)
4582 && !reg_mentioned_p (iy_reg
, src
))
4587 info
->need_save_z
= 0;
4589 else if (TARGET_M6812
&& side_effects_p (src
))
4592 info
->must_restore_reg
= 0;
4597 info
->save_before_last
= 1;
4599 info
->must_restore_reg
= 0;
4600 info
->last
= NEXT_INSN (insn
);
4602 else if (info
->can_use_d
)
4604 info
->last
= NEXT_INSN (insn
);
4611 if (z_dies_here
&& !reg_mentioned_p (iy_reg
, src
)
4612 && GET_CODE (dst
) == REG
&& REGNO (dst
) == HARD_Y_REGNUM
)
4614 info
->need_save_z
= 0;
4616 info
->last
= NEXT_INSN (insn
);
4617 info
->regno
= HARD_Y_REGNUM
;
4618 info
->must_save_reg
= 0;
4619 info
->must_restore_reg
= 0;
4622 if (rtx_equal_p (src
, z_reg
) && rtx_equal_p (dst
, iy_reg
))
4624 info
->regno
= HARD_Y_REGNUM
;
4625 info
->must_restore_reg
= 0;
4626 info
->must_save_reg
= 0;
4632 info
->need_save_z
= 0;
4634 if (info
->last
== 0)
4635 info
->last
= NEXT_INSN (insn
);
4638 return info
->last
!= NULL_RTX
? 0 : 1;
4640 if (GET_CODE (body
) == PARALLEL
)
4643 char ix_clobber
= 0;
4644 char iy_clobber
= 0;
4646 this_insn_uses_iy
= 0;
4647 this_insn_uses_ix
= 0;
4648 this_insn_uses_z
= 0;
4650 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
4653 int uses_ix
, uses_iy
, uses_z
;
4655 x
= XVECEXP (body
, 0, i
);
4657 if (info
->can_use_d
&& reg_mentioned_p (d_reg
, x
))
4658 info
->can_use_d
= 0;
4660 uses_ix
= reg_mentioned_p (ix_reg
, x
);
4661 uses_iy
= reg_mentioned_p (iy_reg
, x
);
4662 uses_z
= reg_mentioned_p (z_reg
, x
);
4663 if (GET_CODE (x
) == CLOBBER
)
4665 ix_clobber
|= uses_ix
;
4666 iy_clobber
|= uses_iy
;
4667 z_clobber
|= uses_z
;
4671 this_insn_uses_ix
|= uses_ix
;
4672 this_insn_uses_iy
|= uses_iy
;
4673 this_insn_uses_z
|= uses_z
;
4675 if (uses_z
&& GET_CODE (x
) == SET
)
4677 rtx dst
= XEXP (x
, 0);
4680 info
->z_set_count
++;
4682 if (TARGET_M6812
&& uses_z
&& side_effects_p (x
))
4683 info
->need_save_z
= 1;
4686 info
->need_save_z
= 0;
4690 printf ("Uses X:%d Y:%d Z:%d CX:%d CY:%d CZ:%d\n",
4691 this_insn_uses_ix
, this_insn_uses_iy
,
4692 this_insn_uses_z
, ix_clobber
, iy_clobber
, z_clobber
);
4695 if (this_insn_uses_z
)
4696 info
->can_use_d
= 0;
4698 if (z_clobber
&& info
->first
!= insn
)
4700 info
->need_save_z
= 0;
4704 if (z_clobber
&& info
->x_used
== 0 && info
->y_used
== 0)
4706 if (this_insn_uses_z
== 0 && insn
== info
->first
)
4708 info
->must_load_z
= 0;
4710 if (dead_register_here (insn
, d_reg
))
4712 info
->regno
= HARD_D_REGNUM
;
4713 info
->must_save_reg
= 0;
4714 info
->must_restore_reg
= 0;
4716 else if (dead_register_here (insn
, ix_reg
))
4718 info
->regno
= HARD_X_REGNUM
;
4719 info
->must_save_reg
= 0;
4720 info
->must_restore_reg
= 0;
4722 else if (dead_register_here (insn
, iy_reg
))
4724 info
->regno
= HARD_Y_REGNUM
;
4725 info
->must_save_reg
= 0;
4726 info
->must_restore_reg
= 0;
4728 if (info
->regno
>= 0)
4730 info
->last
= NEXT_INSN (insn
);
4733 if (this_insn_uses_ix
== 0)
4735 info
->regno
= HARD_X_REGNUM
;
4736 info
->must_save_reg
= 1;
4737 info
->must_restore_reg
= 1;
4739 else if (this_insn_uses_iy
== 0)
4741 info
->regno
= HARD_Y_REGNUM
;
4742 info
->must_save_reg
= 1;
4743 info
->must_restore_reg
= 1;
4747 info
->regno
= HARD_D_REGNUM
;
4748 info
->must_save_reg
= 1;
4749 info
->must_restore_reg
= 1;
4751 info
->last
= NEXT_INSN (insn
);
4755 if (((info
->x_used
|| this_insn_uses_ix
) && iy_clobber
)
4756 || ((info
->y_used
|| this_insn_uses_iy
) && ix_clobber
))
4758 if (this_insn_uses_z
)
4760 if (info
->y_used
== 0 && iy_clobber
)
4762 info
->regno
= HARD_Y_REGNUM
;
4763 info
->must_save_reg
= 0;
4764 info
->must_restore_reg
= 0;
4766 if (info
->first
!= insn
4767 && ((info
->y_used
&& ix_clobber
)
4768 || (info
->x_used
&& iy_clobber
)))
4771 info
->last
= NEXT_INSN (insn
);
4772 info
->save_before_last
= 1;
4776 if (this_insn_uses_ix
&& this_insn_uses_iy
)
4778 if (this_insn_uses_z
)
4780 fatal_insn ("cannot do z-register replacement", insn
);
4784 if (info
->x_used
== 0 && (this_insn_uses_ix
|| ix_clobber
))
4791 if (iy_clobber
|| z_clobber
)
4793 info
->last
= NEXT_INSN (insn
);
4794 info
->save_before_last
= 1;
4799 if (info
->y_used
== 0 && (this_insn_uses_iy
|| iy_clobber
))
4806 if (ix_clobber
|| z_clobber
)
4808 info
->last
= NEXT_INSN (insn
);
4809 info
->save_before_last
= 1;
4816 info
->need_save_z
= 0;
4820 if (GET_CODE (body
) == CLOBBER
)
4823 /* IX and IY are used at the same time, we have to restore
4824 the value of the scratch register before this insn. */
4825 if (this_insn_uses_ix
&& this_insn_uses_iy
)
4829 if (info
->x_used
== 0 && this_insn_uses_ix
)
4837 if (info
->y_used
== 0 && this_insn_uses_iy
)
4851 m68hc11_find_z_replacement (rtx insn
, struct replace_info
*info
)
4855 info
->replace_reg
= NULL_RTX
;
4856 info
->must_load_z
= 1;
4857 info
->need_save_z
= 1;
4858 info
->must_save_reg
= 1;
4859 info
->must_restore_reg
= 1;
4863 info
->can_use_d
= TARGET_M6811
? 1 : 0;
4864 info
->found_call
= 0;
4868 info
->z_set_count
= 0;
4869 info
->z_value
= NULL_RTX
;
4870 info
->must_push_reg
= 0;
4871 info
->save_before_last
= 0;
4872 info
->z_loaded_with_sp
= 0;
4874 /* Scan the insn forward to find an address register that is not used.
4876 - the flow of the program changes,
4877 - when we detect that both X and Y are necessary,
4878 - when the Z register dies,
4879 - when the condition codes are set. */
4881 for (; insn
&& info
->z_died
== 0; insn
= NEXT_INSN (insn
))
4883 if (m68hc11_check_z_replacement (insn
, info
) == 0)
4887 /* May be we can use Y or X if they contain the same value as Z.
4888 This happens very often after the reload. */
4889 if (info
->z_set_count
== 1)
4891 rtx p
= info
->first
;
4896 v
= find_last_value (iy_reg
, &p
, insn
, 1);
4898 else if (info
->y_used
)
4900 v
= find_last_value (ix_reg
, &p
, insn
, 1);
4902 if (v
&& (v
!= iy_reg
&& v
!= ix_reg
) && rtx_equal_p (v
, info
->z_value
))
4905 info
->regno
= HARD_Y_REGNUM
;
4907 info
->regno
= HARD_X_REGNUM
;
4908 info
->must_load_z
= 0;
4909 info
->must_save_reg
= 0;
4910 info
->must_restore_reg
= 0;
4911 info
->found_call
= 1;
4914 if (info
->z_set_count
== 0)
4915 info
->need_save_z
= 0;
4918 info
->need_save_z
= 0;
4920 if (info
->last
== 0)
4923 if (info
->regno
>= 0)
4926 info
->replace_reg
= gen_rtx_REG (HImode
, reg
);
4928 else if (info
->can_use_d
)
4930 reg
= HARD_D_REGNUM
;
4931 info
->replace_reg
= d_reg
;
4933 else if (info
->x_used
)
4935 reg
= HARD_Y_REGNUM
;
4936 info
->replace_reg
= iy_reg
;
4940 reg
= HARD_X_REGNUM
;
4941 info
->replace_reg
= ix_reg
;
4945 if (info
->must_save_reg
&& info
->must_restore_reg
)
4947 if (insn
&& dead_register_here (insn
, info
->replace_reg
))
4949 info
->must_save_reg
= 0;
4950 info
->must_restore_reg
= 0;
4955 /* The insn uses the Z register. Find a replacement register for it
4956 (either X or Y) and replace it in the insn and the next ones until
4957 the flow changes or the replacement register is used. Instructions
4958 are emitted before and after the Z-block to preserve the value of
4959 Z and of the replacement register. */
4962 m68hc11_z_replacement (rtx insn
)
4966 struct replace_info info
;
4968 /* Find trivial case where we only need to replace z with the
4969 equivalent soft register. */
4970 if (GET_CODE (insn
) == INSN
&& GET_CODE (PATTERN (insn
)) == SET
)
4972 rtx body
= PATTERN (insn
);
4973 rtx src
= XEXP (body
, 1);
4974 rtx dst
= XEXP (body
, 0);
4976 if (Z_REG_P (dst
) && (H_REG_P (src
) && !SP_REG_P (src
)))
4978 XEXP (body
, 0) = gen_rtx_REG (GET_MODE (dst
), SOFT_Z_REGNUM
);
4981 else if (Z_REG_P (src
)
4982 && ((H_REG_P (dst
) && !SP_REG_P (src
)) || dst
== cc0_rtx
))
4984 XEXP (body
, 1) = gen_rtx_REG (GET_MODE (src
), SOFT_Z_REGNUM
);
4987 else if (D_REG_P (dst
)
4988 && m68hc11_arith_operator (src
, GET_MODE (src
))
4989 && D_REG_P (XEXP (src
, 0)) && Z_REG_P (XEXP (src
, 1)))
4991 XEXP (src
, 1) = gen_rtx_REG (GET_MODE (src
), SOFT_Z_REGNUM
);
4994 else if (Z_REG_P (dst
) && GET_CODE (src
) == CONST_INT
4995 && INTVAL (src
) == 0)
4997 XEXP (body
, 0) = gen_rtx_REG (GET_MODE (dst
), SOFT_Z_REGNUM
);
4998 /* Force it to be re-recognized. */
4999 INSN_CODE (insn
) = -1;
5004 m68hc11_find_z_replacement (insn
, &info
);
5006 replace_reg
= info
.replace_reg
;
5007 replace_reg_qi
= NULL_RTX
;
5009 /* Save the X register in a .page0 location. */
5010 if (info
.must_save_reg
&& !info
.must_push_reg
)
5014 if (info
.must_push_reg
&& 0)
5015 dst
= gen_rtx_MEM (HImode
,
5016 gen_rtx_PRE_DEC (HImode
,
5017 gen_rtx_REG (HImode
, HARD_SP_REGNUM
)));
5019 dst
= gen_rtx_REG (HImode
, SOFT_SAVED_XY_REGNUM
);
5021 emit_insn_before (gen_movhi (dst
,
5022 gen_rtx_REG (HImode
, info
.regno
)), insn
);
5024 if (info
.must_load_z
&& !info
.must_push_reg
)
5026 emit_insn_before (gen_movhi (gen_rtx_REG (HImode
, info
.regno
),
5027 gen_rtx_REG (HImode
, SOFT_Z_REGNUM
)),
5032 /* Replace all occurrence of Z by replace_reg.
5033 Stop when the last instruction to replace is reached.
5034 Also stop when we detect a change in the flow (but it's not
5035 necessary; just safeguard). */
5037 for (; insn
&& insn
!= info
.last
; insn
= NEXT_INSN (insn
))
5041 if (GET_CODE (insn
) == CODE_LABEL
|| GET_CODE (insn
) == BARRIER
)
5044 if (GET_CODE (insn
) != INSN
5045 && GET_CODE (insn
) != CALL_INSN
&& GET_CODE (insn
) != JUMP_INSN
)
5048 body
= PATTERN (insn
);
5049 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == PARALLEL
5050 || GET_CODE (body
) == ASM_OPERANDS
5051 || GET_CODE (insn
) == CALL_INSN
|| GET_CODE (insn
) == JUMP_INSN
)
5055 if (debug_m6811
&& reg_mentioned_p (replace_reg
, body
))
5057 printf ("Reg mentioned here...:\n");
5062 /* Stack pointer was decremented by 2 due to the push.
5063 Correct that by adding 2 to the destination. */
5064 if (info
.must_push_reg
5065 && info
.z_loaded_with_sp
&& GET_CODE (body
) == SET
)
5069 src
= SET_SRC (body
);
5070 dst
= SET_DEST (body
);
5071 if (SP_REG_P (src
) && Z_REG_P (dst
))
5072 emit_insn_after (gen_addhi3 (dst
, dst
, const2_rtx
), insn
);
5075 /* Replace any (REG:HI Z) occurrence by either X or Y. */
5076 if (!validate_replace_rtx (z_reg
, replace_reg
, insn
))
5078 INSN_CODE (insn
) = -1;
5079 if (!validate_replace_rtx (z_reg
, replace_reg
, insn
))
5080 fatal_insn ("cannot do z-register replacement", insn
);
5083 /* Likewise for (REG:QI Z). */
5084 if (reg_mentioned_p (z_reg
, insn
))
5086 if (replace_reg_qi
== NULL_RTX
)
5087 replace_reg_qi
= gen_rtx_REG (QImode
, REGNO (replace_reg
));
5088 validate_replace_rtx (z_reg_qi
, replace_reg_qi
, insn
);
5091 /* If there is a REG_INC note on Z, replace it with a
5092 REG_INC note on the replacement register. This is necessary
5093 to make sure that the flow pass will identify the change
5094 and it will not remove a possible insn that saves Z. */
5095 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
5097 if (REG_NOTE_KIND (note
) == REG_INC
5098 && GET_CODE (XEXP (note
, 0)) == REG
5099 && REGNO (XEXP (note
, 0)) == REGNO (z_reg
))
5101 XEXP (note
, 0) = replace_reg
;
5105 if (GET_CODE (insn
) == CALL_INSN
|| GET_CODE (insn
) == JUMP_INSN
)
5109 /* Save Z before restoring the old value. */
5110 if (insn
&& info
.need_save_z
&& !info
.must_push_reg
)
5112 rtx save_pos_insn
= insn
;
5114 /* If Z is clobber by the last insn, we have to save its value
5115 before the last instruction. */
5116 if (info
.save_before_last
)
5117 save_pos_insn
= PREV_INSN (save_pos_insn
);
5119 emit_insn_before (gen_movhi (gen_rtx_REG (HImode
, SOFT_Z_REGNUM
),
5120 gen_rtx_REG (HImode
, info
.regno
)),
5124 if (info
.must_push_reg
&& info
.last
)
5128 body
= PATTERN (info
.last
);
5129 new_body
= gen_rtx_PARALLEL (VOIDmode
,
5131 gen_rtx_USE (VOIDmode
,
5133 gen_rtx_USE (VOIDmode
,
5134 gen_rtx_REG (HImode
,
5136 PATTERN (info
.last
) = new_body
;
5138 /* Force recognition on insn since we changed it. */
5139 INSN_CODE (insn
) = -1;
5141 if (!validate_replace_rtx (z_reg
, replace_reg
, info
.last
))
5143 fatal_insn ("invalid Z register replacement for insn", insn
);
5145 insn
= NEXT_INSN (info
.last
);
5148 /* Restore replacement register unless it was died. */
5149 if (insn
&& info
.must_restore_reg
&& !info
.must_push_reg
)
5153 if (info
.must_push_reg
&& 0)
5154 dst
= gen_rtx_MEM (HImode
,
5155 gen_rtx_POST_INC (HImode
,
5156 gen_rtx_REG (HImode
, HARD_SP_REGNUM
)));
5158 dst
= gen_rtx_REG (HImode
, SOFT_SAVED_XY_REGNUM
);
5160 emit_insn_before (gen_movhi (gen_rtx_REG (HImode
, info
.regno
),
5167 /* Scan all the insn and re-affects some registers
5168 - The Z register (if it was used), is affected to X or Y depending
5169 on the instruction. */
5172 m68hc11_reassign_regs (rtx first
)
5176 ix_reg
= gen_rtx_REG (HImode
, HARD_X_REGNUM
);
5177 iy_reg
= gen_rtx_REG (HImode
, HARD_Y_REGNUM
);
5178 z_reg
= gen_rtx_REG (HImode
, HARD_Z_REGNUM
);
5179 z_reg_qi
= gen_rtx_REG (QImode
, HARD_Z_REGNUM
);
5181 /* Scan all insns to replace Z by X or Y preserving the old value
5182 of X/Y and restoring it afterward. */
5184 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
5188 if (GET_CODE (insn
) == CODE_LABEL
5189 || GET_CODE (insn
) == NOTE
|| GET_CODE (insn
) == BARRIER
)
5195 body
= PATTERN (insn
);
5196 if (GET_CODE (body
) == CLOBBER
|| GET_CODE (body
) == USE
)
5199 if (GET_CODE (body
) == CONST_INT
|| GET_CODE (body
) == ASM_INPUT
5200 || GET_CODE (body
) == ASM_OPERANDS
5201 || GET_CODE (body
) == UNSPEC
|| GET_CODE (body
) == UNSPEC_VOLATILE
)
5204 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == PARALLEL
5205 || GET_CODE (insn
) == CALL_INSN
|| GET_CODE (insn
) == JUMP_INSN
)
5208 /* If Z appears in this insn, replace it in the current insn
5209 and the next ones until the flow changes or we have to
5210 restore back the replacement register. */
5212 if (reg_mentioned_p (z_reg
, body
))
5214 m68hc11_z_replacement (insn
);
5219 printf ("insn not handled by Z replacement:\n");
5227 /* Machine-dependent reorg pass.
5228 Specific optimizations are defined here:
5229 - this pass changes the Z register into either X or Y
5230 (it preserves X/Y previous values in a memory slot in page0).
5232 When this pass is finished, the global variable
5233 'z_replacement_completed' is set to 2. */
5236 m68hc11_reorg (void)
5241 z_replacement_completed
= 0;
5242 z_reg
= gen_rtx_REG (HImode
, HARD_Z_REGNUM
);
5243 first
= get_insns ();
5245 /* Some RTX are shared at this point. This breaks the Z register
5246 replacement, unshare everything. */
5247 unshare_all_rtl_again (first
);
5249 /* Force a split of all splitable insn. This is necessary for the
5250 Z register replacement mechanism because we end up with basic insns. */
5251 split_all_insns_noflow ();
5254 z_replacement_completed
= 1;
5255 m68hc11_reassign_regs (first
);
5258 compute_bb_for_insn ();
5260 /* After some splitting, there are some opportunities for CSE pass.
5261 This happens quite often when 32-bit or above patterns are split. */
5262 if (optimize
> 0 && split_done
)
5264 reload_cse_regs (first
);
5267 /* Re-create the REG_DEAD notes. These notes are used in the machine
5268 description to use the best assembly directives. */
5271 /* Before recomputing the REG_DEAD notes, remove all of them.
5272 This is necessary because the reload_cse_regs() pass can
5273 have replaced some (MEM) with a register. In that case,
5274 the REG_DEAD that could exist for that register may become
5276 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
5282 pnote
= ®_NOTES (insn
);
5285 if (REG_NOTE_KIND (*pnote
) == REG_DEAD
)
5286 *pnote
= XEXP (*pnote
, 1);
5288 pnote
= &XEXP (*pnote
, 1);
5293 life_analysis (0, PROP_REG_INFO
| PROP_DEATH_NOTES
);
5296 z_replacement_completed
= 2;
5298 /* If optimizing, then go ahead and split insns that must be
5299 split after Z register replacement. This gives more opportunities
5300 for peephole (in particular for consecutives xgdx/xgdy). */
5302 split_all_insns_noflow ();
5304 /* Once insns are split after the z_replacement_completed == 2,
5305 we must not re-run the life_analysis. The xgdx/xgdy patterns
5306 are not recognized and the life_analysis pass removes some
5307 insns because it thinks some (SETs) are noops or made to dead
5308 stores (which is false due to the swap).
5310 Do a simple pass to eliminate the noop set that the final
5311 split could generate (because it was easier for split definition). */
5315 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
5319 if (INSN_DELETED_P (insn
))
5324 /* Remove the (set (R) (R)) insns generated by some splits. */
5325 body
= PATTERN (insn
);
5326 if (GET_CODE (body
) == SET
5327 && rtx_equal_p (SET_SRC (body
), SET_DEST (body
)))
5329 PUT_CODE (insn
, NOTE
);
5330 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
5331 NOTE_SOURCE_FILE (insn
) = 0;
5338 /* Override memcpy */
5341 m68hc11_init_libfuncs (void)
5343 memcpy_libfunc
= init_one_libfunc ("__memcpy");
5344 memcmp_libfunc
= init_one_libfunc ("__memcmp");
5345 memset_libfunc
= init_one_libfunc ("__memset");
5350 /* Cost functions. */
5352 /* Cost of moving memory. */
5354 m68hc11_memory_move_cost (enum machine_mode mode
, enum reg_class
class,
5355 int in ATTRIBUTE_UNUSED
)
5357 if (class <= H_REGS
&& class > NO_REGS
)
5359 if (GET_MODE_SIZE (mode
) <= 2)
5360 return COSTS_N_INSNS (1) + (reload_completed
| reload_in_progress
);
5362 return COSTS_N_INSNS (2) + (reload_completed
| reload_in_progress
);
5366 if (GET_MODE_SIZE (mode
) <= 2)
5367 return COSTS_N_INSNS (3);
5369 return COSTS_N_INSNS (4);
5374 /* Cost of moving data from a register of class 'from' to on in class 'to'.
5375 Reload does not check the constraint of set insns when the two registers
5376 have a move cost of 2. Setting a higher cost will force reload to check
5379 m68hc11_register_move_cost (enum machine_mode mode
, enum reg_class from
,
5382 /* All costs are symmetric, so reduce cases by putting the
5383 lower number class as the destination. */
5386 enum reg_class tmp
= to
;
5387 to
= from
, from
= tmp
;
5390 return m68hc11_memory_move_cost (mode
, S_REGS
, 0);
5391 else if (from
<= S_REGS
)
5392 return COSTS_N_INSNS (1) + (reload_completed
| reload_in_progress
);
5394 return COSTS_N_INSNS (2);
5398 /* Provide the costs of an addressing mode that contains ADDR.
5399 If ADDR is not a valid address, its cost is irrelevant. */
5402 m68hc11_address_cost (rtx addr
)
5406 switch (GET_CODE (addr
))
5409 /* Make the cost of hard registers and specially SP, FP small. */
5410 if (REGNO (addr
) < FIRST_PSEUDO_REGISTER
)
5427 register rtx plus0
= XEXP (addr
, 0);
5428 register rtx plus1
= XEXP (addr
, 1);
5430 if (GET_CODE (plus0
) != REG
)
5433 switch (GET_CODE (plus1
))
5436 if (INTVAL (plus1
) >= 2 * m68hc11_max_offset
5437 || INTVAL (plus1
) < m68hc11_min_offset
)
5439 else if (INTVAL (plus1
) >= m68hc11_max_offset
)
5443 if (REGNO (plus0
) < FIRST_PSEUDO_REGISTER
)
5465 if (SP_REG_P (XEXP (addr
, 0)))
5474 printf ("Address cost: %d for :", cost
);
5483 m68hc11_shift_cost (enum machine_mode mode
, rtx x
, int shift
)
5487 total
= rtx_cost (x
, SET
);
5489 total
+= m68hc11_cost
->shiftQI_const
[shift
% 8];
5490 else if (mode
== HImode
)
5491 total
+= m68hc11_cost
->shiftHI_const
[shift
% 16];
5492 else if (shift
== 8 || shift
== 16 || shift
== 32)
5493 total
+= m68hc11_cost
->shiftHI_const
[8];
5494 else if (shift
!= 0 && shift
!= 16 && shift
!= 32)
5496 total
+= m68hc11_cost
->shiftHI_const
[1] * shift
;
5499 /* For SI and others, the cost is higher. */
5500 if (GET_MODE_SIZE (mode
) > 2 && (shift
% 16) != 0)
5501 total
*= GET_MODE_SIZE (mode
) / 2;
5503 /* When optimizing for size, make shift more costly so that
5504 multiplications are preferred. */
5505 if (optimize_size
&& (shift
% 8) != 0)
5512 m68hc11_rtx_costs_1 (rtx x
, enum rtx_code code
,
5513 enum rtx_code outer_code ATTRIBUTE_UNUSED
)
5515 enum machine_mode mode
= GET_MODE (x
);
5526 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
5528 return m68hc11_shift_cost (mode
, XEXP (x
, 0), INTVAL (XEXP (x
, 1)));
5531 total
= rtx_cost (XEXP (x
, 0), code
) + rtx_cost (XEXP (x
, 1), code
);
5532 total
+= m68hc11_cost
->shift_var
;
5538 total
= rtx_cost (XEXP (x
, 0), code
) + rtx_cost (XEXP (x
, 1), code
);
5539 total
+= m68hc11_cost
->logical
;
5541 /* Logical instructions are byte instructions only. */
5542 total
*= GET_MODE_SIZE (mode
);
5547 total
= rtx_cost (XEXP (x
, 0), code
) + rtx_cost (XEXP (x
, 1), code
);
5548 total
+= m68hc11_cost
->add
;
5549 if (GET_MODE_SIZE (mode
) > 2)
5551 total
*= GET_MODE_SIZE (mode
) / 2;
5558 total
= rtx_cost (XEXP (x
, 0), code
) + rtx_cost (XEXP (x
, 1), code
);
5562 total
+= m68hc11_cost
->divQI
;
5566 total
+= m68hc11_cost
->divHI
;
5571 total
+= m68hc11_cost
->divSI
;
5577 /* mul instruction produces 16-bit result. */
5578 if (mode
== HImode
&& GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
5579 && GET_CODE (XEXP (x
, 1)) == ZERO_EXTEND
)
5580 return m68hc11_cost
->multQI
5581 + rtx_cost (XEXP (XEXP (x
, 0), 0), code
)
5582 + rtx_cost (XEXP (XEXP (x
, 1), 0), code
);
5584 /* emul instruction produces 32-bit result for 68HC12. */
5585 if (TARGET_M6812
&& mode
== SImode
5586 && GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
5587 && GET_CODE (XEXP (x
, 1)) == ZERO_EXTEND
)
5588 return m68hc11_cost
->multHI
5589 + rtx_cost (XEXP (XEXP (x
, 0), 0), code
)
5590 + rtx_cost (XEXP (XEXP (x
, 1), 0), code
);
5592 total
= rtx_cost (XEXP (x
, 0), code
) + rtx_cost (XEXP (x
, 1), code
);
5596 total
+= m68hc11_cost
->multQI
;
5600 total
+= m68hc11_cost
->multHI
;
5605 total
+= m68hc11_cost
->multSI
;
5612 extra_cost
= COSTS_N_INSNS (2);
5619 total
= extra_cost
+ rtx_cost (XEXP (x
, 0), code
);
5622 return total
+ COSTS_N_INSNS (1);
5626 return total
+ COSTS_N_INSNS (2);
5630 return total
+ COSTS_N_INSNS (4);
5632 return total
+ COSTS_N_INSNS (8);
5635 if (GET_CODE (XEXP (x
, 1)) == PC
|| GET_CODE (XEXP (x
, 2)) == PC
)
5636 return COSTS_N_INSNS (1);
5638 return COSTS_N_INSNS (1);
5641 return COSTS_N_INSNS (4);
5646 m68hc11_rtx_costs (rtx x
, int code
, int outer_code
, int *total
)
5650 /* Constants are cheap. Moving them in registers must be avoided
5651 because most instructions do not handle two register operands. */
5657 /* Logical and arithmetic operations with a constant operand are
5658 better because they are not supported with two registers. */
5660 if (outer_code
== SET
&& x
== const0_rtx
)
5661 /* After reload, the reload_cse pass checks the cost to change
5662 a SET into a PLUS. Make const0 cheap then. */
5663 *total
= 1 - reload_completed
;
5688 *total
= m68hc11_rtx_costs_1 (x
, code
, outer_code
);
5697 /* Worker function for TARGET_ASM_FILE_START. */
5700 m68hc11_file_start (void)
5702 default_file_start ();
5704 fprintf (asm_out_file
, "\t.mode %s\n", TARGET_SHORT
? "mshort" : "mlong");
5708 /* Worker function for TARGET_ASM_CONSTRUCTOR. */
5711 m68hc11_asm_out_constructor (rtx symbol
, int priority
)
5713 default_ctor_section_asm_out_constructor (symbol
, priority
);
5714 fprintf (asm_out_file
, "\t.globl\t__do_global_ctors\n");
5717 /* Worker function for TARGET_ASM_DESTRUCTOR. */
5720 m68hc11_asm_out_destructor (rtx symbol
, int priority
)
5722 default_dtor_section_asm_out_destructor (symbol
, priority
);
5723 fprintf (asm_out_file
, "\t.globl\t__do_global_dtors\n");
5726 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
5729 m68hc11_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
5730 int incoming ATTRIBUTE_UNUSED
)
5732 return gen_rtx_REG (Pmode
, HARD_D_REGNUM
);
5735 /* Return true if type TYPE should be returned in memory.
5736 Blocks and data types largers than 4 bytes cannot be returned
5737 in the register (D + X = 4). */
5740 m68hc11_return_in_memory (tree type
, tree fntype ATTRIBUTE_UNUSED
)
5742 if (TYPE_MODE (type
) == BLKmode
)
5744 HOST_WIDE_INT size
= int_size_in_bytes (type
);
5745 return (size
== -1 || size
> 4);
5748 return GET_MODE_SIZE (TYPE_MODE (type
)) > 4;
5751 #include "gt-m68hc11.h"