annotate gcc/config/cr16/cr16.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Output routines for CR16 processor.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2012-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by KPIT Cummins Infosystems Limited.
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
8 under the terms of the GNU General Public License as published
kono
parents:
diff changeset
9 by the Free Software Foundation; either version 3, or (at your
kono
parents:
diff changeset
10 option) any later version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT
kono
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
kono
parents:
diff changeset
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
kono
parents:
diff changeset
15 License for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
21 #define IN_TARGET_CODE 1
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
22
111
kono
parents:
diff changeset
23 #include "config.h"
kono
parents:
diff changeset
24 #include "system.h"
kono
parents:
diff changeset
25 #include "coretypes.h"
kono
parents:
diff changeset
26 #include "backend.h"
kono
parents:
diff changeset
27 #include "target.h"
kono
parents:
diff changeset
28 #include "rtl.h"
kono
parents:
diff changeset
29 #include "tree.h"
kono
parents:
diff changeset
30 #include "stringpool.h"
kono
parents:
diff changeset
31 #include "attribs.h"
kono
parents:
diff changeset
32 #include "df.h"
kono
parents:
diff changeset
33 #include "memmodel.h"
kono
parents:
diff changeset
34 #include "tm_p.h"
kono
parents:
diff changeset
35 #include "regs.h"
kono
parents:
diff changeset
36 #include "emit-rtl.h"
kono
parents:
diff changeset
37 #include "diagnostic-core.h"
kono
parents:
diff changeset
38 #include "stor-layout.h"
kono
parents:
diff changeset
39 #include "calls.h"
kono
parents:
diff changeset
40 #include "conditions.h"
kono
parents:
diff changeset
41 #include "output.h"
kono
parents:
diff changeset
42 #include "expr.h"
kono
parents:
diff changeset
43 #include "builtins.h"
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 /* This file should be included last. */
kono
parents:
diff changeset
46 #include "target-def.h"
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 /* Definitions. */
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 /* Maximum number of register used for passing parameters. */
kono
parents:
diff changeset
51 #define MAX_REG_FOR_PASSING_ARGS 6
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 /* Minimum number register used for passing parameters. */
kono
parents:
diff changeset
54 #define MIN_REG_FOR_PASSING_ARGS 2
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 /* The maximum count of words supported in the assembly of the architecture in
kono
parents:
diff changeset
57 a push/pop instruction. */
kono
parents:
diff changeset
58 #define MAX_COUNT 8
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 /* Predicate is true if the current function is a 'noreturn' function,
kono
parents:
diff changeset
61 i.e. it is qualified as volatile. */
kono
parents:
diff changeset
62 #define FUNC_IS_NORETURN_P(decl) (TREE_THIS_VOLATILE (decl))
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 /* Predicate that holds when we need to save registers even for 'noreturn'
kono
parents:
diff changeset
65 functions, to accommodate for unwinding. */
kono
parents:
diff changeset
66 #define MUST_SAVE_REGS_P() \
kono
parents:
diff changeset
67 (flag_unwind_tables || (flag_exceptions && !UI_SJLJ))
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 /* Nonzero if the rtx X is a signed const int of n bits. */
kono
parents:
diff changeset
70 #define RTX_SIGNED_INT_FITS_N_BITS(X, n) \
kono
parents:
diff changeset
71 ((GET_CODE (X) == CONST_INT \
kono
parents:
diff changeset
72 && SIGNED_INT_FITS_N_BITS (INTVAL (X), n)) ? 1 : 0)
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 /* Nonzero if the rtx X is an unsigned const int of n bits. */
kono
parents:
diff changeset
75 #define RTX_UNSIGNED_INT_FITS_N_BITS(X, n) \
kono
parents:
diff changeset
76 ((GET_CODE (X) == CONST_INT \
kono
parents:
diff changeset
77 && UNSIGNED_INT_FITS_N_BITS (INTVAL (X), n)) ? 1 : 0)
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 /* Structure for stack computations. */
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 /* variable definitions in the struture
kono
parents:
diff changeset
82 args_size Number of bytes saved on the stack for local
kono
parents:
diff changeset
83 variables
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 reg_size Number of bytes saved on the stack for
kono
parents:
diff changeset
86 non-scratch registers
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 total_size The sum of 2 sizes: locals vars and padding byte
kono
parents:
diff changeset
89 for saving the registers. Used in expand_prologue()
kono
parents:
diff changeset
90 and expand_epilogue()
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 last_reg_to_save Will hold the number of the last register the
kono
parents:
diff changeset
93 prologue saves, -1 if no register is saved
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 save_regs[16] Each object in the array is a register number.
kono
parents:
diff changeset
96 Mark 1 for registers that need to be saved
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 num_regs Number of registers saved
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 initialized Non-zero if frame size already calculated, not
kono
parents:
diff changeset
101 used yet
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 function_makes_calls Does the function make calls ? not used yet. */
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 struct cr16_frame_info
kono
parents:
diff changeset
106 {
kono
parents:
diff changeset
107 unsigned long var_size;
kono
parents:
diff changeset
108 unsigned long args_size;
kono
parents:
diff changeset
109 unsigned int reg_size;
kono
parents:
diff changeset
110 unsigned long total_size;
kono
parents:
diff changeset
111 long last_reg_to_save;
kono
parents:
diff changeset
112 long save_regs[FIRST_PSEUDO_REGISTER];
kono
parents:
diff changeset
113 int num_regs;
kono
parents:
diff changeset
114 int initialized;
kono
parents:
diff changeset
115 int function_makes_calls;
kono
parents:
diff changeset
116 };
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 /* Current frame information calculated by cr16_compute_frame_size. */
kono
parents:
diff changeset
119 static struct cr16_frame_info current_frame_info;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 /* Static Variables. */
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 /* Data model that was supplied by user via command line option
kono
parents:
diff changeset
124 This will be overridden in case of invalid combination
kono
parents:
diff changeset
125 of core and data model options are supplied. */
kono
parents:
diff changeset
126 static enum data_model_type data_model = DM_DEFAULT;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 /* TARGETM Function Prototypes and forward declarations */
kono
parents:
diff changeset
129 static void cr16_print_operand (FILE *, rtx, int);
kono
parents:
diff changeset
130 static void cr16_print_operand_address (FILE *, machine_mode, rtx);
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 /* Stack layout and calling conventions. */
kono
parents:
diff changeset
133 #undef TARGET_STRUCT_VALUE_RTX
kono
parents:
diff changeset
134 #define TARGET_STRUCT_VALUE_RTX cr16_struct_value_rtx
kono
parents:
diff changeset
135 #undef TARGET_RETURN_IN_MEMORY
kono
parents:
diff changeset
136 #define TARGET_RETURN_IN_MEMORY cr16_return_in_memory
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 /* Target-specific uses of '__attribute__'. */
kono
parents:
diff changeset
139 #undef TARGET_ATTRIBUTE_TABLE
kono
parents:
diff changeset
140 #define TARGET_ATTRIBUTE_TABLE cr16_attribute_table
kono
parents:
diff changeset
141 #undef TARGET_NARROW_VOLATILE_BITFIELD
kono
parents:
diff changeset
142 #define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 /* EH related. */
kono
parents:
diff changeset
145 #undef TARGET_UNWIND_WORD_MODE
kono
parents:
diff changeset
146 #define TARGET_UNWIND_WORD_MODE cr16_unwind_word_mode
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 /* Override Options. */
kono
parents:
diff changeset
149 #undef TARGET_OPTION_OVERRIDE
kono
parents:
diff changeset
150 #define TARGET_OPTION_OVERRIDE cr16_override_options
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 /* Conditional register usuage. */
kono
parents:
diff changeset
153 #undef TARGET_CONDITIONAL_REGISTER_USAGE
kono
parents:
diff changeset
154 #define TARGET_CONDITIONAL_REGISTER_USAGE cr16_conditional_register_usage
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 /* Controlling register spills. */
kono
parents:
diff changeset
157 #undef TARGET_CLASS_LIKELY_SPILLED_P
kono
parents:
diff changeset
158 #define TARGET_CLASS_LIKELY_SPILLED_P cr16_class_likely_spilled_p
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 /* Passing function arguments. */
kono
parents:
diff changeset
161 #undef TARGET_FUNCTION_ARG
kono
parents:
diff changeset
162 #define TARGET_FUNCTION_ARG cr16_function_arg
kono
parents:
diff changeset
163 #undef TARGET_FUNCTION_ARG_ADVANCE
kono
parents:
diff changeset
164 #define TARGET_FUNCTION_ARG_ADVANCE cr16_function_arg_advance
kono
parents:
diff changeset
165 #undef TARGET_RETURN_POPS_ARGS
kono
parents:
diff changeset
166 #define TARGET_RETURN_POPS_ARGS cr16_return_pops_args
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 /* Initialize the GCC target structure. */
kono
parents:
diff changeset
169 #undef TARGET_FRAME_POINTER_REQUIRED
kono
parents:
diff changeset
170 #define TARGET_FRAME_POINTER_REQUIRED cr16_frame_pointer_required
kono
parents:
diff changeset
171 #undef TARGET_CAN_ELIMINATE
kono
parents:
diff changeset
172 #define TARGET_CAN_ELIMINATE cr16_can_eliminate
kono
parents:
diff changeset
173 #undef TARGET_LEGITIMIZE_ADDRESS
kono
parents:
diff changeset
174 #define TARGET_LEGITIMIZE_ADDRESS cr16_legitimize_address
kono
parents:
diff changeset
175 #undef TARGET_LEGITIMATE_CONSTANT_P
kono
parents:
diff changeset
176 #define TARGET_LEGITIMATE_CONSTANT_P cr16_legitimate_constant_p
kono
parents:
diff changeset
177 #undef TARGET_LEGITIMATE_ADDRESS_P
kono
parents:
diff changeset
178 #define TARGET_LEGITIMATE_ADDRESS_P cr16_legitimate_address_p
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 #undef TARGET_LRA_P
kono
parents:
diff changeset
181 #define TARGET_LRA_P hook_bool_void_false
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 /* Returning function value. */
kono
parents:
diff changeset
184 #undef TARGET_FUNCTION_VALUE
kono
parents:
diff changeset
185 #define TARGET_FUNCTION_VALUE cr16_function_value
kono
parents:
diff changeset
186 #undef TARGET_LIBCALL_VALUE
kono
parents:
diff changeset
187 #define TARGET_LIBCALL_VALUE cr16_libcall_value
kono
parents:
diff changeset
188 #undef TARGET_FUNCTION_VALUE_REGNO_P
kono
parents:
diff changeset
189 #define TARGET_FUNCTION_VALUE_REGNO_P cr16_function_value_regno_p
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 /* printing the values. */
kono
parents:
diff changeset
192 #undef TARGET_PRINT_OPERAND
kono
parents:
diff changeset
193 #define TARGET_PRINT_OPERAND cr16_print_operand
kono
parents:
diff changeset
194 #undef TARGET_PRINT_OPERAND_ADDRESS
kono
parents:
diff changeset
195 #define TARGET_PRINT_OPERAND_ADDRESS cr16_print_operand_address
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 /* Relative costs of operations. */
kono
parents:
diff changeset
198 #undef TARGET_ADDRESS_COST
kono
parents:
diff changeset
199 #define TARGET_ADDRESS_COST cr16_address_cost
kono
parents:
diff changeset
200 #undef TARGET_REGISTER_MOVE_COST
kono
parents:
diff changeset
201 #define TARGET_REGISTER_MOVE_COST cr16_register_move_cost
kono
parents:
diff changeset
202 #undef TARGET_MEMORY_MOVE_COST
kono
parents:
diff changeset
203 #define TARGET_MEMORY_MOVE_COST cr16_memory_move_cost
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 #undef TARGET_CONSTANT_ALIGNMENT
kono
parents:
diff changeset
206 #define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 /* Table of machine attributes. */
kono
parents:
diff changeset
209 static const struct attribute_spec cr16_attribute_table[] = {
kono
parents:
diff changeset
210 /* ISRs have special prologue and epilogue requirements. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
211 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
212 affects_type_identity, handler, exclude }. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
213 {"interrupt", 0, 0, false, true, true, false, NULL, NULL},
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
214 {NULL, 0, 0, false, false, false, false, NULL, NULL}
111
kono
parents:
diff changeset
215 };
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 /* TARGET_ASM_UNALIGNED_xx_OP generates .?byte directive
kono
parents:
diff changeset
218 .?byte directive along with @c is not understood by assembler.
kono
parents:
diff changeset
219 Therefore, make all TARGET_ASM_UNALIGNED_xx_OP same
kono
parents:
diff changeset
220 as TARGET_ASM_ALIGNED_xx_OP. */
kono
parents:
diff changeset
221 #undef TARGET_ASM_UNALIGNED_HI_OP
kono
parents:
diff changeset
222 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
kono
parents:
diff changeset
223 #undef TARGET_ASM_UNALIGNED_SI_OP
kono
parents:
diff changeset
224 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
kono
parents:
diff changeset
225 #undef TARGET_ASM_UNALIGNED_DI_OP
kono
parents:
diff changeset
226 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 #undef TARGET_HARD_REGNO_NREGS
kono
parents:
diff changeset
229 #define TARGET_HARD_REGNO_NREGS cr16_hard_regno_nregs
kono
parents:
diff changeset
230 #undef TARGET_HARD_REGNO_MODE_OK
kono
parents:
diff changeset
231 #define TARGET_HARD_REGNO_MODE_OK cr16_hard_regno_mode_ok
kono
parents:
diff changeset
232 #undef TARGET_MODES_TIEABLE_P
kono
parents:
diff changeset
233 #define TARGET_MODES_TIEABLE_P cr16_modes_tieable_p
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 /* Target hook implementations. */
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 /* Implements hook TARGET_RETURN_IN_MEMORY. */
kono
parents:
diff changeset
238 static bool
kono
parents:
diff changeset
239 cr16_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
240 {
kono
parents:
diff changeset
241 const HOST_WIDE_INT size = int_size_in_bytes (type);
kono
parents:
diff changeset
242 return ((size == -1) || (size > 8));
kono
parents:
diff changeset
243 }
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 /* Implement TARGET_CLASS_LIKELY_SPILLED_P. */
kono
parents:
diff changeset
246 static bool
kono
parents:
diff changeset
247 cr16_class_likely_spilled_p (reg_class_t rclass)
kono
parents:
diff changeset
248 {
kono
parents:
diff changeset
249 if ((rclass) == SHORT_REGS || (rclass) == DOUBLE_BASE_REGS
kono
parents:
diff changeset
250 || (rclass) == LONG_REGS || (rclass) == GENERAL_REGS)
kono
parents:
diff changeset
251 return true;
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 return false;
kono
parents:
diff changeset
254 }
kono
parents:
diff changeset
255
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
256 static poly_int64
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
257 cr16_return_pops_args (tree, tree, poly_int64)
111
kono
parents:
diff changeset
258 {
kono
parents:
diff changeset
259 return 0;
kono
parents:
diff changeset
260 }
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 /* Returns true if data model selected via command line option
kono
parents:
diff changeset
263 is same as function argument. */
kono
parents:
diff changeset
264 bool
kono
parents:
diff changeset
265 cr16_is_data_model (enum data_model_type model)
kono
parents:
diff changeset
266 {
kono
parents:
diff changeset
267 return (model == data_model);
kono
parents:
diff changeset
268 }
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 /* Parse relevant options and override. */
kono
parents:
diff changeset
271 static void
kono
parents:
diff changeset
272 cr16_override_options (void)
kono
parents:
diff changeset
273 {
kono
parents:
diff changeset
274 /* Disable -fdelete-null-pointer-checks option for CR16 target.
kono
parents:
diff changeset
275 Programs which rely on NULL pointer dereferences _not_ halting the
kono
parents:
diff changeset
276 program may not work properly with this option. So disable this
kono
parents:
diff changeset
277 option. */
kono
parents:
diff changeset
278 flag_delete_null_pointer_checks = 0;
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 /* FIXME: To avoid spill_failure ICE during exception handling,
kono
parents:
diff changeset
281 * disable cse_fllow_jumps. The spill error occurs when compiler
kono
parents:
diff changeset
282 * can't find a suitable candidate in GENERAL_REGS class to reload
kono
parents:
diff changeset
283 * a 32bit register.
kono
parents:
diff changeset
284 * Need to find a better way of avoiding this situation. */
kono
parents:
diff changeset
285 if (flag_exceptions)
kono
parents:
diff changeset
286 flag_cse_follow_jumps = 0;
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 /* If -fpic option, data_model == DM_FAR. */
kono
parents:
diff changeset
289 if (flag_pic == NEAR_PIC)
kono
parents:
diff changeset
290 {
kono
parents:
diff changeset
291 data_model = DM_FAR;
kono
parents:
diff changeset
292 }
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 /* The only option we want to examine is data model option. */
kono
parents:
diff changeset
295 if (cr16_data_model)
kono
parents:
diff changeset
296 {
kono
parents:
diff changeset
297 if (strcmp (cr16_data_model, "medium") == 0)
kono
parents:
diff changeset
298 data_model = DM_DEFAULT;
kono
parents:
diff changeset
299 else if (strcmp (cr16_data_model, "near") == 0)
kono
parents:
diff changeset
300 data_model = DM_NEAR;
kono
parents:
diff changeset
301 else if (strcmp (cr16_data_model, "far") == 0)
kono
parents:
diff changeset
302 {
kono
parents:
diff changeset
303 if (TARGET_CR16CP)
kono
parents:
diff changeset
304 data_model = DM_FAR;
kono
parents:
diff changeset
305 else
kono
parents:
diff changeset
306 error ("data-model=far not valid for cr16c architecture");
kono
parents:
diff changeset
307 }
kono
parents:
diff changeset
308 else
kono
parents:
diff changeset
309 error ("invalid data model option -mdata-model=%s", cr16_data_model);
kono
parents:
diff changeset
310 }
kono
parents:
diff changeset
311 else
kono
parents:
diff changeset
312 data_model = DM_DEFAULT;
kono
parents:
diff changeset
313 }
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 /* Implements the macro TARGET_CONDITIONAL_REGISTER_USAGE. */
kono
parents:
diff changeset
316 static void
kono
parents:
diff changeset
317 cr16_conditional_register_usage (void)
kono
parents:
diff changeset
318 {
kono
parents:
diff changeset
319 if (flag_pic)
kono
parents:
diff changeset
320 {
kono
parents:
diff changeset
321 fixed_regs[12] = call_used_regs[12] = 1;
kono
parents:
diff changeset
322 }
kono
parents:
diff changeset
323 }
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 /* Stack layout and calling conventions routines. */
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 /* Return nonzero if the current function being compiled is an interrupt
kono
parents:
diff changeset
328 function as specified by the "interrupt" attribute. */
kono
parents:
diff changeset
329 int
kono
parents:
diff changeset
330 cr16_interrupt_function_p (void)
kono
parents:
diff changeset
331 {
kono
parents:
diff changeset
332 tree attributes;
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 attributes = TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl));
kono
parents:
diff changeset
335 return (lookup_attribute ("interrupt", attributes) != NULL_TREE);
kono
parents:
diff changeset
336 }
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 /* Compute values for the array current_frame_info.save_regs and the variable
kono
parents:
diff changeset
339 current_frame_info.reg_size. The index of current_frame_info.save_regs
kono
parents:
diff changeset
340 is numbers of register, each will get 1 if we need to save it in the
kono
parents:
diff changeset
341 current function, 0 if not. current_frame_info.reg_size is the total sum
kono
parents:
diff changeset
342 of the registers being saved. */
kono
parents:
diff changeset
343 static void
kono
parents:
diff changeset
344 cr16_compute_save_regs (void)
kono
parents:
diff changeset
345 {
kono
parents:
diff changeset
346 unsigned int regno;
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 /* Initialize here so in case the function is no-return it will be -1. */
kono
parents:
diff changeset
349 current_frame_info.last_reg_to_save = -1;
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 /* Initialize the number of bytes to be saved. */
kono
parents:
diff changeset
352 current_frame_info.reg_size = 0;
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 /* No need to save any registers if the function never returns. */
kono
parents:
diff changeset
355 if (FUNC_IS_NORETURN_P (current_function_decl) && !MUST_SAVE_REGS_P ())
kono
parents:
diff changeset
356 return;
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
kono
parents:
diff changeset
359 {
kono
parents:
diff changeset
360 if (fixed_regs[regno])
kono
parents:
diff changeset
361 {
kono
parents:
diff changeset
362 current_frame_info.save_regs[regno] = 0;
kono
parents:
diff changeset
363 continue;
kono
parents:
diff changeset
364 }
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 /* If this reg is used and not call-used (except RA), save it. */
kono
parents:
diff changeset
367 if (cr16_interrupt_function_p ())
kono
parents:
diff changeset
368 {
kono
parents:
diff changeset
369 if (!crtl->is_leaf && call_used_regs[regno])
kono
parents:
diff changeset
370 /* This is a volatile reg in a non-leaf interrupt routine - save
kono
parents:
diff changeset
371 it for the sake of its sons. */
kono
parents:
diff changeset
372 current_frame_info.save_regs[regno] = 1;
kono
parents:
diff changeset
373 else if (df_regs_ever_live_p (regno))
kono
parents:
diff changeset
374 /* This reg is used - save it. */
kono
parents:
diff changeset
375 current_frame_info.save_regs[regno] = 1;
kono
parents:
diff changeset
376 else
kono
parents:
diff changeset
377 /* This reg is not used, and is not a volatile - don't save. */
kono
parents:
diff changeset
378 current_frame_info.save_regs[regno] = 0;
kono
parents:
diff changeset
379 }
kono
parents:
diff changeset
380 else
kono
parents:
diff changeset
381 {
kono
parents:
diff changeset
382 /* If this reg is used and not call-used (except RA), save it. */
kono
parents:
diff changeset
383 if (df_regs_ever_live_p (regno)
kono
parents:
diff changeset
384 && (!call_used_regs[regno] || regno == RETURN_ADDRESS_REGNUM))
kono
parents:
diff changeset
385 current_frame_info.save_regs[regno] = 1;
kono
parents:
diff changeset
386 else
kono
parents:
diff changeset
387 current_frame_info.save_regs[regno] = 0;
kono
parents:
diff changeset
388 }
kono
parents:
diff changeset
389 }
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 /* Save registers so the exception handler can modify them. */
kono
parents:
diff changeset
392 if (crtl->calls_eh_return)
kono
parents:
diff changeset
393 {
kono
parents:
diff changeset
394 unsigned int i;
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 for (i = 0;; ++i)
kono
parents:
diff changeset
397 {
kono
parents:
diff changeset
398 regno = EH_RETURN_DATA_REGNO (i);
kono
parents:
diff changeset
399 if (INVALID_REGNUM == regno)
kono
parents:
diff changeset
400 break;
kono
parents:
diff changeset
401 current_frame_info.save_regs[regno] = 1;
kono
parents:
diff changeset
402 }
kono
parents:
diff changeset
403 }
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
kono
parents:
diff changeset
406 if (current_frame_info.save_regs[regno] == 1)
kono
parents:
diff changeset
407 {
kono
parents:
diff changeset
408 current_frame_info.last_reg_to_save = regno;
kono
parents:
diff changeset
409 if (regno >= CR16_FIRST_DWORD_REGISTER)
kono
parents:
diff changeset
410 current_frame_info.reg_size += CR16_UNITS_PER_DWORD;
kono
parents:
diff changeset
411 else
kono
parents:
diff changeset
412 current_frame_info.reg_size += UNITS_PER_WORD;
kono
parents:
diff changeset
413 }
kono
parents:
diff changeset
414 }
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 /* Compute the size of the local area and the size to be adjusted by the
kono
parents:
diff changeset
417 prologue and epilogue. */
kono
parents:
diff changeset
418 static void
kono
parents:
diff changeset
419 cr16_compute_frame (void)
kono
parents:
diff changeset
420 {
kono
parents:
diff changeset
421 /* For aligning the local variables. */
kono
parents:
diff changeset
422 int stack_alignment = STACK_BOUNDARY / BITS_PER_UNIT;
kono
parents:
diff changeset
423 int padding_locals;
kono
parents:
diff changeset
424
kono
parents:
diff changeset
425 /* Padding needed for each element of the frame. */
kono
parents:
diff changeset
426 current_frame_info.var_size = get_frame_size ();
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 /* Align to the stack alignment. */
kono
parents:
diff changeset
429 padding_locals = current_frame_info.var_size % stack_alignment;
kono
parents:
diff changeset
430 if (padding_locals)
kono
parents:
diff changeset
431 padding_locals = stack_alignment - padding_locals;
kono
parents:
diff changeset
432
kono
parents:
diff changeset
433 current_frame_info.var_size += padding_locals;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
434 current_frame_info.total_size
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
435 = (current_frame_info.var_size
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
436 + (ACCUMULATE_OUTGOING_ARGS
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
437 ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0));
111
kono
parents:
diff changeset
438 }
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 /* Implements the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET. */
kono
parents:
diff changeset
441 int
kono
parents:
diff changeset
442 cr16_initial_elimination_offset (int from, int to)
kono
parents:
diff changeset
443 {
kono
parents:
diff changeset
444 /* Compute this since we need to use current_frame_info.reg_size. */
kono
parents:
diff changeset
445 cr16_compute_save_regs ();
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 /* Compute this since we need to use current_frame_info.var_size. */
kono
parents:
diff changeset
448 cr16_compute_frame ();
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 if (((from) == FRAME_POINTER_REGNUM) && ((to) == STACK_POINTER_REGNUM))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
451 return (ACCUMULATE_OUTGOING_ARGS
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
452 ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0);
111
kono
parents:
diff changeset
453 else if (((from) == ARG_POINTER_REGNUM) && ((to) == FRAME_POINTER_REGNUM))
kono
parents:
diff changeset
454 return (current_frame_info.reg_size + current_frame_info.var_size);
kono
parents:
diff changeset
455 else if (((from) == ARG_POINTER_REGNUM) && ((to) == STACK_POINTER_REGNUM))
kono
parents:
diff changeset
456 return (current_frame_info.reg_size + current_frame_info.var_size
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
457 + (ACCUMULATE_OUTGOING_ARGS
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
458 ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0));
111
kono
parents:
diff changeset
459 else
kono
parents:
diff changeset
460 gcc_unreachable ();
kono
parents:
diff changeset
461 }
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 /* Register Usage. */
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 /* Return the class number of the smallest class containing reg number REGNO.
kono
parents:
diff changeset
466 This could be a conditional expression or could index an array. */
kono
parents:
diff changeset
467 enum reg_class
kono
parents:
diff changeset
468 cr16_regno_reg_class (int regno)
kono
parents:
diff changeset
469 {
kono
parents:
diff changeset
470 if ((regno >= 0) && (regno < CR16_FIRST_DWORD_REGISTER))
kono
parents:
diff changeset
471 return SHORT_REGS;
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 if ((regno >= CR16_FIRST_DWORD_REGISTER) && (regno < FIRST_PSEUDO_REGISTER))
kono
parents:
diff changeset
474 return LONG_REGS;
kono
parents:
diff changeset
475
kono
parents:
diff changeset
476 return NO_REGS;
kono
parents:
diff changeset
477 }
kono
parents:
diff changeset
478
kono
parents:
diff changeset
479 /* Implement TARGET_HARD_REGNO_NREGS. */
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 static unsigned int
kono
parents:
diff changeset
482 cr16_hard_regno_nregs (unsigned int regno, machine_mode mode)
kono
parents:
diff changeset
483 {
kono
parents:
diff changeset
484 if (regno >= CR16_FIRST_DWORD_REGISTER)
kono
parents:
diff changeset
485 return CEIL (GET_MODE_SIZE (mode), CR16_UNITS_PER_DWORD);
kono
parents:
diff changeset
486 return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD);
kono
parents:
diff changeset
487 }
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 /* Implement TARGET_HARD_REGNO_MODE_OK. On the CR16 architecture, all
kono
parents:
diff changeset
490 registers can hold all modes, except that double precision floats
kono
parents:
diff changeset
491 (and double ints) must fall on even-register boundaries. */
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 static bool
kono
parents:
diff changeset
494 cr16_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
kono
parents:
diff changeset
495 {
kono
parents:
diff changeset
496 if ((GET_MODE_SIZE (mode) >= 4) && (regno == 11))
kono
parents:
diff changeset
497 return false;
kono
parents:
diff changeset
498
kono
parents:
diff changeset
499 if (mode == DImode || mode == DFmode)
kono
parents:
diff changeset
500 {
kono
parents:
diff changeset
501 if ((regno > 8) || (regno & 1))
kono
parents:
diff changeset
502 return false;
kono
parents:
diff changeset
503 return true;
kono
parents:
diff changeset
504 }
kono
parents:
diff changeset
505
kono
parents:
diff changeset
506 if ((TARGET_INT32)
kono
parents:
diff changeset
507 && ((regno >= 12) && (GET_MODE_SIZE (mode) < 4 )))
kono
parents:
diff changeset
508 return false;
kono
parents:
diff changeset
509
kono
parents:
diff changeset
510 /* CC can only hold CCmode values. */
kono
parents:
diff changeset
511 if (GET_MODE_CLASS (mode) == MODE_CC)
kono
parents:
diff changeset
512 return false;
kono
parents:
diff changeset
513 return true;
kono
parents:
diff changeset
514 }
kono
parents:
diff changeset
515
kono
parents:
diff changeset
516 /* Implement TARGET_MODES_TIEABLE_P. */
kono
parents:
diff changeset
517 static bool
kono
parents:
diff changeset
518 cr16_modes_tieable_p (machine_mode mode1, machine_mode mode2)
kono
parents:
diff changeset
519 {
kono
parents:
diff changeset
520 return GET_MODE_CLASS (mode1) == GET_MODE_CLASS (mode2);
kono
parents:
diff changeset
521 }
kono
parents:
diff changeset
522
kono
parents:
diff changeset
523 /* Returns register number for function return value.*/
kono
parents:
diff changeset
524 static inline unsigned int
kono
parents:
diff changeset
525 cr16_ret_register (void)
kono
parents:
diff changeset
526 {
kono
parents:
diff changeset
527 return 0;
kono
parents:
diff changeset
528 }
kono
parents:
diff changeset
529
kono
parents:
diff changeset
530 /* Implements hook TARGET_STRUCT_VALUE_RTX. */
kono
parents:
diff changeset
531 static rtx
kono
parents:
diff changeset
532 cr16_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
533 int incoming ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
534 {
kono
parents:
diff changeset
535 return gen_rtx_REG (Pmode, cr16_ret_register ());
kono
parents:
diff changeset
536 }
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538 /* Returning function value. */
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 /* Worker function for TARGET_FUNCTION_VALUE_REGNO_P. */
kono
parents:
diff changeset
541 static bool
kono
parents:
diff changeset
542 cr16_function_value_regno_p (const unsigned int regno)
kono
parents:
diff changeset
543 {
kono
parents:
diff changeset
544 return (regno == cr16_ret_register ());
kono
parents:
diff changeset
545 }
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 /* Create an RTX representing the place where a
kono
parents:
diff changeset
548 library function returns a value of mode MODE. */
kono
parents:
diff changeset
549 static rtx
kono
parents:
diff changeset
550 cr16_libcall_value (machine_mode mode,
kono
parents:
diff changeset
551 const_rtx func ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
552 {
kono
parents:
diff changeset
553 return gen_rtx_REG (mode, cr16_ret_register ());
kono
parents:
diff changeset
554 }
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 /* Create an RTX representing the place where a
kono
parents:
diff changeset
557 function returns a value of data type VALTYPE. */
kono
parents:
diff changeset
558 static rtx
kono
parents:
diff changeset
559 cr16_function_value (const_tree type,
kono
parents:
diff changeset
560 const_tree fn_decl_or_type ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
561 bool outgoing ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
562 {
kono
parents:
diff changeset
563 return gen_rtx_REG (TYPE_MODE (type), cr16_ret_register ());
kono
parents:
diff changeset
564 }
kono
parents:
diff changeset
565
kono
parents:
diff changeset
566 /* Passing function arguments. */
kono
parents:
diff changeset
567
kono
parents:
diff changeset
568 /* If enough param regs are available for passing the param of type TYPE return
kono
parents:
diff changeset
569 the number of registers needed else 0. */
kono
parents:
diff changeset
570 static int
kono
parents:
diff changeset
571 enough_regs_for_param (CUMULATIVE_ARGS * cum, const_tree type,
kono
parents:
diff changeset
572 machine_mode mode)
kono
parents:
diff changeset
573 {
kono
parents:
diff changeset
574 int type_size;
kono
parents:
diff changeset
575 int remaining_size;
kono
parents:
diff changeset
576
kono
parents:
diff changeset
577 if (mode != BLKmode)
kono
parents:
diff changeset
578 type_size = GET_MODE_BITSIZE (mode);
kono
parents:
diff changeset
579 else
kono
parents:
diff changeset
580 type_size = int_size_in_bytes (type) * BITS_PER_UNIT;
kono
parents:
diff changeset
581
kono
parents:
diff changeset
582 remaining_size = BITS_PER_WORD * (MAX_REG_FOR_PASSING_ARGS
kono
parents:
diff changeset
583 - (MIN_REG_FOR_PASSING_ARGS + cum->ints) +
kono
parents:
diff changeset
584 1);
kono
parents:
diff changeset
585
kono
parents:
diff changeset
586 /* Any variable which is too big to pass in two registers, will pass on
kono
parents:
diff changeset
587 stack. */
kono
parents:
diff changeset
588 if ((remaining_size >= type_size) && (type_size <= 2 * BITS_PER_WORD))
kono
parents:
diff changeset
589 return (type_size + BITS_PER_WORD - 1) / BITS_PER_WORD;
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 return 0;
kono
parents:
diff changeset
592 }
kono
parents:
diff changeset
593
kono
parents:
diff changeset
594 /* Implements the macro FUNCTION_ARG defined in cr16.h. */
kono
parents:
diff changeset
595 static rtx
kono
parents:
diff changeset
596 cr16_function_arg (cumulative_args_t cum_v, machine_mode mode,
kono
parents:
diff changeset
597 const_tree type, bool named ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
598 {
kono
parents:
diff changeset
599 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
kono
parents:
diff changeset
600 cum->last_parm_in_reg = 0;
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 /* function_arg () is called with this type just after all the args have
kono
parents:
diff changeset
603 had their registers assigned. The rtx that function_arg returns from
kono
parents:
diff changeset
604 this type is supposed to pass to 'gen_call' but currently it is not
kono
parents:
diff changeset
605 implemented. */
kono
parents:
diff changeset
606 if (type == void_type_node)
kono
parents:
diff changeset
607 return NULL_RTX;
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 if (targetm.calls.must_pass_in_stack (mode, type) || (cum->ints < 0))
kono
parents:
diff changeset
610 return NULL_RTX;
kono
parents:
diff changeset
611
kono
parents:
diff changeset
612 if (mode == BLKmode)
kono
parents:
diff changeset
613 {
kono
parents:
diff changeset
614 /* Enable structures that need padding bytes at the end to pass to a
kono
parents:
diff changeset
615 function in registers. */
kono
parents:
diff changeset
616 if (enough_regs_for_param (cum, type, mode) != 0)
kono
parents:
diff changeset
617 {
kono
parents:
diff changeset
618 cum->last_parm_in_reg = 1;
kono
parents:
diff changeset
619 return gen_rtx_REG (mode, MIN_REG_FOR_PASSING_ARGS + cum->ints);
kono
parents:
diff changeset
620 }
kono
parents:
diff changeset
621 }
kono
parents:
diff changeset
622
kono
parents:
diff changeset
623 if ((MIN_REG_FOR_PASSING_ARGS + cum->ints) > MAX_REG_FOR_PASSING_ARGS)
kono
parents:
diff changeset
624 return NULL_RTX;
kono
parents:
diff changeset
625 else
kono
parents:
diff changeset
626 {
kono
parents:
diff changeset
627 if (enough_regs_for_param (cum, type, mode) != 0)
kono
parents:
diff changeset
628 {
kono
parents:
diff changeset
629 cum->last_parm_in_reg = 1;
kono
parents:
diff changeset
630 return gen_rtx_REG (mode, MIN_REG_FOR_PASSING_ARGS + cum->ints);
kono
parents:
diff changeset
631 }
kono
parents:
diff changeset
632 }
kono
parents:
diff changeset
633
kono
parents:
diff changeset
634 return NULL_RTX;
kono
parents:
diff changeset
635 }
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 /* Implements the macro INIT_CUMULATIVE_ARGS defined in cr16.h. */
kono
parents:
diff changeset
638 void
kono
parents:
diff changeset
639 cr16_init_cumulative_args (CUMULATIVE_ARGS * cum, tree fntype,
kono
parents:
diff changeset
640 rtx libfunc ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
641 {
kono
parents:
diff changeset
642 tree param, next_param;
kono
parents:
diff changeset
643
kono
parents:
diff changeset
644 cum->ints = 0;
kono
parents:
diff changeset
645
kono
parents:
diff changeset
646 /* Determine if this function has variable arguments. This is indicated by
kono
parents:
diff changeset
647 the last argument being 'void_type_mode' if there are no variable
kono
parents:
diff changeset
648 arguments. Change here for a different vararg. */
kono
parents:
diff changeset
649 for (param = (fntype) ? TYPE_ARG_TYPES (fntype) : 0;
kono
parents:
diff changeset
650 param != NULL_TREE; param = next_param)
kono
parents:
diff changeset
651 {
kono
parents:
diff changeset
652 next_param = TREE_CHAIN (param);
kono
parents:
diff changeset
653 if ((next_param == NULL_TREE) && (TREE_VALUE (param) != void_type_node))
kono
parents:
diff changeset
654 {
kono
parents:
diff changeset
655 cum->ints = -1;
kono
parents:
diff changeset
656 return;
kono
parents:
diff changeset
657 }
kono
parents:
diff changeset
658 }
kono
parents:
diff changeset
659 }
kono
parents:
diff changeset
660
kono
parents:
diff changeset
661 /* Implements the macro FUNCTION_ARG_ADVANCE defined in cr16.h. */
kono
parents:
diff changeset
662 static void
kono
parents:
diff changeset
663 cr16_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
kono
parents:
diff changeset
664 const_tree type, bool named ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
665 {
kono
parents:
diff changeset
666 CUMULATIVE_ARGS * cum = get_cumulative_args (cum_v);
kono
parents:
diff changeset
667
kono
parents:
diff changeset
668 /* l holds the number of registers required. */
kono
parents:
diff changeset
669 int l = GET_MODE_BITSIZE (mode) / BITS_PER_WORD;
kono
parents:
diff changeset
670
kono
parents:
diff changeset
671 /* If the parameter isn't passed on a register don't advance cum. */
kono
parents:
diff changeset
672 if (!cum->last_parm_in_reg)
kono
parents:
diff changeset
673 return;
kono
parents:
diff changeset
674
kono
parents:
diff changeset
675 if (targetm.calls.must_pass_in_stack (mode, type) || (cum->ints < 0))
kono
parents:
diff changeset
676 return;
kono
parents:
diff changeset
677
kono
parents:
diff changeset
678 if ((mode == SImode) || (mode == HImode)
kono
parents:
diff changeset
679 || (mode == QImode) || (mode == DImode))
kono
parents:
diff changeset
680 {
kono
parents:
diff changeset
681 if (l <= 1)
kono
parents:
diff changeset
682 cum->ints += 1;
kono
parents:
diff changeset
683 else
kono
parents:
diff changeset
684 cum->ints += l;
kono
parents:
diff changeset
685 }
kono
parents:
diff changeset
686 else if ((mode == SFmode) || (mode == DFmode))
kono
parents:
diff changeset
687 cum->ints += l;
kono
parents:
diff changeset
688 else if ((mode) == BLKmode)
kono
parents:
diff changeset
689 {
kono
parents:
diff changeset
690 if ((l = enough_regs_for_param (cum, type, mode)) != 0)
kono
parents:
diff changeset
691 cum->ints += l;
kono
parents:
diff changeset
692 }
kono
parents:
diff changeset
693 return;
kono
parents:
diff changeset
694 }
kono
parents:
diff changeset
695
kono
parents:
diff changeset
696 /* Implements the macro FUNCTION_ARG_REGNO_P defined in cr16.h.
kono
parents:
diff changeset
697 Return nonzero if N is a register used for passing parameters. */
kono
parents:
diff changeset
698 int
kono
parents:
diff changeset
699 cr16_function_arg_regno_p (int n)
kono
parents:
diff changeset
700 {
kono
parents:
diff changeset
701 return ((n <= MAX_REG_FOR_PASSING_ARGS) && (n >= MIN_REG_FOR_PASSING_ARGS));
kono
parents:
diff changeset
702 }
kono
parents:
diff changeset
703
kono
parents:
diff changeset
704 /* Addressing modes.
kono
parents:
diff changeset
705 Following set of function implement the macro GO_IF_LEGITIMATE_ADDRESS
kono
parents:
diff changeset
706 defined in cr16.h. */
kono
parents:
diff changeset
707
kono
parents:
diff changeset
708 /* Helper function to check if is a valid base register that can
kono
parents:
diff changeset
709 hold address. */
kono
parents:
diff changeset
710 static int
kono
parents:
diff changeset
711 cr16_addr_reg_p (rtx addr_reg)
kono
parents:
diff changeset
712 {
kono
parents:
diff changeset
713 rtx reg;
kono
parents:
diff changeset
714
kono
parents:
diff changeset
715 if (REG_P (addr_reg))
kono
parents:
diff changeset
716 reg = addr_reg;
kono
parents:
diff changeset
717 else if ((GET_CODE (addr_reg) == SUBREG)
kono
parents:
diff changeset
718 && REG_P (SUBREG_REG (addr_reg))
kono
parents:
diff changeset
719 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (addr_reg)))
kono
parents:
diff changeset
720 <= UNITS_PER_WORD))
kono
parents:
diff changeset
721 reg = SUBREG_REG (addr_reg);
kono
parents:
diff changeset
722 else
kono
parents:
diff changeset
723 return FALSE;
kono
parents:
diff changeset
724
kono
parents:
diff changeset
725 if (GET_MODE (reg) != Pmode)
kono
parents:
diff changeset
726 return FALSE;
kono
parents:
diff changeset
727
kono
parents:
diff changeset
728 return TRUE;
kono
parents:
diff changeset
729 }
kono
parents:
diff changeset
730
kono
parents:
diff changeset
731 /* Helper functions: Created specifically for decomposing operand of CONST
kono
parents:
diff changeset
732 Recursively look into expression x for code or data symbol.
kono
parents:
diff changeset
733 The function expects the expression to contain combination of
kono
parents:
diff changeset
734 SYMBOL_REF, CONST_INT, (PLUS or MINUS)
kono
parents:
diff changeset
735 LABEL_REF, CONST_INT, (PLUS or MINUS)
kono
parents:
diff changeset
736 SYMBOL_REF
kono
parents:
diff changeset
737 LABEL_REF
kono
parents:
diff changeset
738 All other combinations will result in code = -1 and data = ILLEGAL_DM
kono
parents:
diff changeset
739 code data
kono
parents:
diff changeset
740 -1 ILLEGAL_DM The expression did not contain SYMBOL_REF or LABEL_REF
kono
parents:
diff changeset
741 0 DM_FAR SYMBOL_REF was found and it was far data reference.
kono
parents:
diff changeset
742 0 DM_DEFAULT SYMBOL_REF was found and it was medium data reference.
kono
parents:
diff changeset
743 1 ILLEGAL_DM LABEL_REF was found.
kono
parents:
diff changeset
744 2 ILLEGAL_DM SYMBOL_REF was found and it was function reference. */
kono
parents:
diff changeset
745 void
kono
parents:
diff changeset
746 cr16_decompose_const (rtx x, int *code, enum data_model_type *data,
kono
parents:
diff changeset
747 bool treat_as_const)
kono
parents:
diff changeset
748 {
kono
parents:
diff changeset
749 *code = -1;
kono
parents:
diff changeset
750 *data = ILLEGAL_DM;
kono
parents:
diff changeset
751 switch (GET_CODE (x))
kono
parents:
diff changeset
752 {
kono
parents:
diff changeset
753 case SYMBOL_REF:
kono
parents:
diff changeset
754 *code = SYMBOL_REF_FUNCTION_P (x) ? 2 : 0;
kono
parents:
diff changeset
755 /* 2 indicates func sym. */
kono
parents:
diff changeset
756 if (*code == 0)
kono
parents:
diff changeset
757 {
kono
parents:
diff changeset
758 if (CR16_TARGET_DATA_NEAR)
kono
parents:
diff changeset
759 *data = DM_DEFAULT;
kono
parents:
diff changeset
760 else if (CR16_TARGET_DATA_MEDIUM)
kono
parents:
diff changeset
761 *data = DM_FAR;
kono
parents:
diff changeset
762 else if (CR16_TARGET_DATA_FAR)
kono
parents:
diff changeset
763 {
kono
parents:
diff changeset
764 if (treat_as_const)
kono
parents:
diff changeset
765 /* This will be used only for printing
kono
parents:
diff changeset
766 the qualifier. This call is (may be)
kono
parents:
diff changeset
767 made by cr16_print_operand_address. */
kono
parents:
diff changeset
768 *data = DM_FAR;
kono
parents:
diff changeset
769 else
kono
parents:
diff changeset
770 /* This call is (may be) made by
kono
parents:
diff changeset
771 cr16_legitimate_address_p. */
kono
parents:
diff changeset
772 *data = ILLEGAL_DM;
kono
parents:
diff changeset
773 }
kono
parents:
diff changeset
774 }
kono
parents:
diff changeset
775 return;
kono
parents:
diff changeset
776
kono
parents:
diff changeset
777 case LABEL_REF:
kono
parents:
diff changeset
778 /* 1 - indicates non-function symbol. */
kono
parents:
diff changeset
779 *code = 1;
kono
parents:
diff changeset
780 return;
kono
parents:
diff changeset
781
kono
parents:
diff changeset
782 case PLUS:
kono
parents:
diff changeset
783 case MINUS:
kono
parents:
diff changeset
784 /* Look into the tree nodes. */
kono
parents:
diff changeset
785 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
kono
parents:
diff changeset
786 cr16_decompose_const (XEXP (x, 1), code, data, treat_as_const);
kono
parents:
diff changeset
787 else if (GET_CODE (XEXP (x, 1)) == CONST_INT)
kono
parents:
diff changeset
788 cr16_decompose_const (XEXP (x, 0), code, data, treat_as_const);
kono
parents:
diff changeset
789 return;
kono
parents:
diff changeset
790 default:
kono
parents:
diff changeset
791 return;
kono
parents:
diff changeset
792 }
kono
parents:
diff changeset
793 }
kono
parents:
diff changeset
794
kono
parents:
diff changeset
795 /* Decompose Address
kono
parents:
diff changeset
796 This function decomposes the address returns the type of address
kono
parents:
diff changeset
797 as defined in enum cr16_addrtype. It also fills the parameter *out.
kono
parents:
diff changeset
798 The decomposed address can be used for two purposes. One to
kono
parents:
diff changeset
799 check if the address is valid and second to print the address
kono
parents:
diff changeset
800 operand.
kono
parents:
diff changeset
801
kono
parents:
diff changeset
802 Following tables list valid address supported in CR16C/C+ architectures.
kono
parents:
diff changeset
803 Legend:
kono
parents:
diff changeset
804 aN : Absoulte address N-bit address
kono
parents:
diff changeset
805 R : One 16-bit register
kono
parents:
diff changeset
806 RP : Consecutive two 16-bit registers or one 32-bit register
kono
parents:
diff changeset
807 I : One 32-bit register
kono
parents:
diff changeset
808 dispN : Signed displacement of N-bits
kono
parents:
diff changeset
809
kono
parents:
diff changeset
810 ----Code addresses----
kono
parents:
diff changeset
811 Branch operands:
kono
parents:
diff changeset
812 disp9 : CR16_ABSOLUTE (disp)
kono
parents:
diff changeset
813 disp17 : CR16_ABSOLUTE (disp)
kono
parents:
diff changeset
814 disp25 : CR16_ABSOLUTE (disp)
kono
parents:
diff changeset
815 RP + disp25 : CR16_REGP_REL (base, disp)
kono
parents:
diff changeset
816
kono
parents:
diff changeset
817 Jump operands:
kono
parents:
diff changeset
818 RP : CR16_REGP_REL (base, disp=0)
kono
parents:
diff changeset
819 a24 : CR16_ABSOLUTE (disp)
kono
parents:
diff changeset
820
kono
parents:
diff changeset
821 ----Data addresses----
kono
parents:
diff changeset
822 a20 : CR16_ABSOLUTE (disp) near (1M)
kono
parents:
diff changeset
823 a24 : CR16_ABSOLUTE (disp) medium (16M)
kono
parents:
diff changeset
824 R + d20 : CR16_REG_REL (base, disp) near (1M+64K)
kono
parents:
diff changeset
825 RP + d4 : CR16_REGP_REL (base, disp) far (4G)
kono
parents:
diff changeset
826 RP + d16 : CR16_REGP_REL (base, disp) far (4G)
kono
parents:
diff changeset
827 RP + d20 : CR16_REGP_REL (base, disp) far (4G)
kono
parents:
diff changeset
828 I : *** Valid but port does not support this
kono
parents:
diff changeset
829 I + a20 : *** Valid but port does not support this
kono
parents:
diff changeset
830 I + RP + d14: CR16_INDEX_REGP_REL (base, index, disp) far (4G)
kono
parents:
diff changeset
831 I + RP + d20: CR16_INDEX_REGP_REL (base, index, disp) far (4G)
kono
parents:
diff changeset
832
kono
parents:
diff changeset
833 Decomposing Data model in case of absolute address.
kono
parents:
diff changeset
834
kono
parents:
diff changeset
835 Target Option Address type Resultant Data ref type
kono
parents:
diff changeset
836 ---------------------- ------------ -----------------------
kono
parents:
diff changeset
837 CR16_TARGET_MODEL_NEAR ABS20 DM_DEFAULT
kono
parents:
diff changeset
838 CR16_TARGET_MODEL_NEAR IMM20 DM_DEFAULT
kono
parents:
diff changeset
839 CR16_TARGET_MODEL_NEAR ABS24 Invalid
kono
parents:
diff changeset
840 CR16_TARGET_MODEL_NEAR IMM32 Invalid
kono
parents:
diff changeset
841
kono
parents:
diff changeset
842 CR16_TARGET_MODEL_MEDIUM ABS20 DM_DEFAULT
kono
parents:
diff changeset
843 CR16_TARGET_MODEL_MEDIUM IMM20 DM_DEFAULT
kono
parents:
diff changeset
844 CR16_TARGET_MODEL_MEDIUM ABS24 DM_FAR
kono
parents:
diff changeset
845 CR16_TARGET_MODEL_MEDIUM IMM32 Invalid
kono
parents:
diff changeset
846
kono
parents:
diff changeset
847 CR16_TARGET_MODEL_FAR ABS20 DM_DEFAULT
kono
parents:
diff changeset
848 CR16_TARGET_MODEL_FAR IMM20 DM_DEFAULT
kono
parents:
diff changeset
849 CR16_TARGET_MODEL_FAR ABS24 DM_FAR
kono
parents:
diff changeset
850 CR16_TARGET_MODEL_FAR IMM32 DM_FAR. */
kono
parents:
diff changeset
851 enum cr16_addrtype
kono
parents:
diff changeset
852 cr16_decompose_address (rtx addr, struct cr16_address *out,
kono
parents:
diff changeset
853 bool debug_print, bool treat_as_const)
kono
parents:
diff changeset
854 {
kono
parents:
diff changeset
855 rtx base = NULL_RTX, disp = NULL_RTX, index = NULL_RTX;
kono
parents:
diff changeset
856 enum data_model_type data = ILLEGAL_DM;
kono
parents:
diff changeset
857 int code = -1;
kono
parents:
diff changeset
858 enum cr16_addrtype retval = CR16_INVALID;
kono
parents:
diff changeset
859
kono
parents:
diff changeset
860 switch (GET_CODE (addr))
kono
parents:
diff changeset
861 {
kono
parents:
diff changeset
862 case CONST_INT:
kono
parents:
diff changeset
863 /* Absolute address (known at compile time). */
kono
parents:
diff changeset
864 code = 0;
kono
parents:
diff changeset
865 if (debug_print)
kono
parents:
diff changeset
866 fprintf (stderr, "\ncode:%d", code);
kono
parents:
diff changeset
867 disp = addr;
kono
parents:
diff changeset
868
kono
parents:
diff changeset
869 if (debug_print)
kono
parents:
diff changeset
870 {
kono
parents:
diff changeset
871 fprintf (stderr, "\ndisp:");
kono
parents:
diff changeset
872 debug_rtx (disp);
kono
parents:
diff changeset
873 }
kono
parents:
diff changeset
874
kono
parents:
diff changeset
875 if (UNSIGNED_INT_FITS_N_BITS (INTVAL (disp), 20))
kono
parents:
diff changeset
876 {
kono
parents:
diff changeset
877 data = DM_DEFAULT;
kono
parents:
diff changeset
878 if (debug_print)
kono
parents:
diff changeset
879 fprintf (stderr, "\ndata:%d", data);
kono
parents:
diff changeset
880 retval = CR16_ABSOLUTE;
kono
parents:
diff changeset
881 }
kono
parents:
diff changeset
882 else if (UNSIGNED_INT_FITS_N_BITS (INTVAL (disp), 24))
kono
parents:
diff changeset
883 {
kono
parents:
diff changeset
884 if (!CR16_TARGET_DATA_NEAR)
kono
parents:
diff changeset
885 {
kono
parents:
diff changeset
886 data = DM_FAR;
kono
parents:
diff changeset
887 if (debug_print)
kono
parents:
diff changeset
888 fprintf (stderr, "\ndata:%d", data);
kono
parents:
diff changeset
889 retval = CR16_ABSOLUTE;
kono
parents:
diff changeset
890 }
kono
parents:
diff changeset
891 else
kono
parents:
diff changeset
892 return CR16_INVALID; /* ABS24 is not support in NEAR model. */
kono
parents:
diff changeset
893 }
kono
parents:
diff changeset
894 else
kono
parents:
diff changeset
895 return CR16_INVALID;
kono
parents:
diff changeset
896 break;
kono
parents:
diff changeset
897
kono
parents:
diff changeset
898 case CONST:
kono
parents:
diff changeset
899 /* A CONST is an expression of PLUS or MINUS with
kono
parents:
diff changeset
900 CONST_INT, SYMBOL_REF or LABEL_REF. This is the
kono
parents:
diff changeset
901 result of assembly-time arithmetic computation. */
kono
parents:
diff changeset
902 retval = CR16_ABSOLUTE;
kono
parents:
diff changeset
903 disp = addr;
kono
parents:
diff changeset
904 /* Call the helper function to check the validity. */
kono
parents:
diff changeset
905 cr16_decompose_const (XEXP (addr, 0), &code, &data, treat_as_const);
kono
parents:
diff changeset
906 if ((code == 0) && (data == ILLEGAL_DM))
kono
parents:
diff changeset
907 /* CONST is not valid code or data address. */
kono
parents:
diff changeset
908 return CR16_INVALID;
kono
parents:
diff changeset
909 if (debug_print)
kono
parents:
diff changeset
910 {
kono
parents:
diff changeset
911 fprintf (stderr, "\ndisp:");
kono
parents:
diff changeset
912 debug_rtx (disp);
kono
parents:
diff changeset
913 fprintf (stderr, "\ncode:%d", code);
kono
parents:
diff changeset
914 fprintf (stderr, "\ndata:%d", data);
kono
parents:
diff changeset
915 }
kono
parents:
diff changeset
916 break;
kono
parents:
diff changeset
917
kono
parents:
diff changeset
918 case LABEL_REF:
kono
parents:
diff changeset
919 retval = CR16_ABSOLUTE;
kono
parents:
diff changeset
920 disp = addr;
kono
parents:
diff changeset
921 /* 1 - indicates non-function symbol. */
kono
parents:
diff changeset
922 code = 1;
kono
parents:
diff changeset
923 if (debug_print)
kono
parents:
diff changeset
924 {
kono
parents:
diff changeset
925 fprintf (stderr, "\ndisp:");
kono
parents:
diff changeset
926 debug_rtx (disp);
kono
parents:
diff changeset
927 fprintf (stderr, "\ncode:%d", code);
kono
parents:
diff changeset
928 }
kono
parents:
diff changeset
929 break;
kono
parents:
diff changeset
930
kono
parents:
diff changeset
931 case SYMBOL_REF:
kono
parents:
diff changeset
932 /* Absolute address (known at link time). */
kono
parents:
diff changeset
933 retval = CR16_ABSOLUTE;
kono
parents:
diff changeset
934 disp = addr;
kono
parents:
diff changeset
935 /* This is a code address if symbol_ref is a function. */
kono
parents:
diff changeset
936 /* 2 indicates func sym. */
kono
parents:
diff changeset
937 code = SYMBOL_REF_FUNCTION_P (addr) ? 2 : 0;
kono
parents:
diff changeset
938 if (debug_print)
kono
parents:
diff changeset
939 {
kono
parents:
diff changeset
940 fprintf (stderr, "\ndisp:");
kono
parents:
diff changeset
941 debug_rtx (disp);
kono
parents:
diff changeset
942 fprintf (stderr, "\ncode:%d", code);
kono
parents:
diff changeset
943 }
kono
parents:
diff changeset
944 /* If not function ref then check if valid data ref. */
kono
parents:
diff changeset
945 if (code == 0)
kono
parents:
diff changeset
946 {
kono
parents:
diff changeset
947 if (CR16_TARGET_DATA_NEAR)
kono
parents:
diff changeset
948 data = DM_DEFAULT;
kono
parents:
diff changeset
949 else if (CR16_TARGET_DATA_MEDIUM)
kono
parents:
diff changeset
950 data = DM_FAR;
kono
parents:
diff changeset
951 else if (CR16_TARGET_DATA_FAR)
kono
parents:
diff changeset
952 {
kono
parents:
diff changeset
953 if (treat_as_const)
kono
parents:
diff changeset
954 /* This will be used only for printing the
kono
parents:
diff changeset
955 qualifier. This call is (may be) made
kono
parents:
diff changeset
956 by cr16_print_operand_address. */
kono
parents:
diff changeset
957 data = DM_FAR;
kono
parents:
diff changeset
958 else
kono
parents:
diff changeset
959 /* This call is (may be) made by
kono
parents:
diff changeset
960 cr16_legitimate_address_p. */
kono
parents:
diff changeset
961 return CR16_INVALID;
kono
parents:
diff changeset
962 }
kono
parents:
diff changeset
963 else
kono
parents:
diff changeset
964 data = DM_DEFAULT;
kono
parents:
diff changeset
965 }
kono
parents:
diff changeset
966 if (debug_print)
kono
parents:
diff changeset
967 fprintf (stderr, "\ndata:%d", data);
kono
parents:
diff changeset
968 break;
kono
parents:
diff changeset
969
kono
parents:
diff changeset
970 case REG:
kono
parents:
diff changeset
971 case SUBREG:
kono
parents:
diff changeset
972 /* Register relative address. */
kono
parents:
diff changeset
973 /* Assume REG fits in a single register. */
kono
parents:
diff changeset
974 retval = CR16_REG_REL;
kono
parents:
diff changeset
975 if (GET_MODE_BITSIZE (GET_MODE (addr)) > BITS_PER_WORD)
kono
parents:
diff changeset
976 if (!LONG_REG_P (REGNO (addr)))
kono
parents:
diff changeset
977 /* REG will result in reg pair. */
kono
parents:
diff changeset
978 retval = CR16_REGP_REL;
kono
parents:
diff changeset
979 base = addr;
kono
parents:
diff changeset
980 if (debug_print)
kono
parents:
diff changeset
981 {
kono
parents:
diff changeset
982 fprintf (stderr, "\nbase:");
kono
parents:
diff changeset
983 debug_rtx (base);
kono
parents:
diff changeset
984 }
kono
parents:
diff changeset
985 break;
kono
parents:
diff changeset
986
kono
parents:
diff changeset
987 case PLUS:
kono
parents:
diff changeset
988 switch (GET_CODE (XEXP (addr, 0)))
kono
parents:
diff changeset
989 {
kono
parents:
diff changeset
990 case REG:
kono
parents:
diff changeset
991 case SUBREG:
kono
parents:
diff changeset
992 /* REG + DISP20. */
kono
parents:
diff changeset
993 /* All Reg relative addresses having a displacement needs
kono
parents:
diff changeset
994 to fit in 20-bits. */
kono
parents:
diff changeset
995 disp = XEXP (addr, 1);
kono
parents:
diff changeset
996 if (debug_print)
kono
parents:
diff changeset
997 {
kono
parents:
diff changeset
998 fprintf (stderr, "\ndisp:");
kono
parents:
diff changeset
999 debug_rtx (disp);
kono
parents:
diff changeset
1000 }
kono
parents:
diff changeset
1001 switch (GET_CODE (XEXP (addr, 1)))
kono
parents:
diff changeset
1002 {
kono
parents:
diff changeset
1003 case CONST_INT:
kono
parents:
diff changeset
1004 /* Shall fit in 20-bits. */
kono
parents:
diff changeset
1005 if (!UNSIGNED_INT_FITS_N_BITS (INTVAL (disp), 20))
kono
parents:
diff changeset
1006 return CR16_INVALID;
kono
parents:
diff changeset
1007 code = 0;
kono
parents:
diff changeset
1008 if (debug_print)
kono
parents:
diff changeset
1009 fprintf (stderr, "\ncode:%d", code);
kono
parents:
diff changeset
1010 break;
kono
parents:
diff changeset
1011
kono
parents:
diff changeset
1012 case UNSPEC:
kono
parents:
diff changeset
1013 switch (XINT (XEXP (addr, 1), 1))
kono
parents:
diff changeset
1014 {
kono
parents:
diff changeset
1015 case UNSPEC_LIBRARY_OFFSET:
kono
parents:
diff changeset
1016 default:
kono
parents:
diff changeset
1017 gcc_unreachable ();
kono
parents:
diff changeset
1018 }
kono
parents:
diff changeset
1019 break;
kono
parents:
diff changeset
1020
kono
parents:
diff changeset
1021 case LABEL_REF:
kono
parents:
diff changeset
1022 case SYMBOL_REF:
kono
parents:
diff changeset
1023 case CONST:
kono
parents:
diff changeset
1024 /* This is also a valid expression for address.
kono
parents:
diff changeset
1025 However, we cannot ascertain if the resultant
kono
parents:
diff changeset
1026 displacement will be valid 20-bit value. Therefore,
kono
parents:
diff changeset
1027 lets not allow such an expression for now. This will
kono
parents:
diff changeset
1028 be updated when we find a way to validate this
kono
parents:
diff changeset
1029 expression as legitimate address.
kono
parents:
diff changeset
1030 Till then fall through CR16_INVALID. */
kono
parents:
diff changeset
1031 default:
kono
parents:
diff changeset
1032 return CR16_INVALID;
kono
parents:
diff changeset
1033 }
kono
parents:
diff changeset
1034
kono
parents:
diff changeset
1035 /* Now check if REG can fit into single or pair regs. */
kono
parents:
diff changeset
1036 retval = CR16_REG_REL;
kono
parents:
diff changeset
1037 base = XEXP (addr, 0);
kono
parents:
diff changeset
1038 if (debug_print)
kono
parents:
diff changeset
1039 {
kono
parents:
diff changeset
1040 fprintf (stderr, "\nbase:");
kono
parents:
diff changeset
1041 debug_rtx (base);
kono
parents:
diff changeset
1042 }
kono
parents:
diff changeset
1043 if (GET_MODE_BITSIZE (GET_MODE ((XEXP (addr, 0)))) > BITS_PER_WORD)
kono
parents:
diff changeset
1044 {
kono
parents:
diff changeset
1045 if (!LONG_REG_P (REGNO ((XEXP (addr, 0)))))
kono
parents:
diff changeset
1046 /* REG will result in reg pair. */
kono
parents:
diff changeset
1047 retval = CR16_REGP_REL;
kono
parents:
diff changeset
1048 }
kono
parents:
diff changeset
1049 break;
kono
parents:
diff changeset
1050
kono
parents:
diff changeset
1051 case PLUS:
kono
parents:
diff changeset
1052 /* Valid expr:
kono
parents:
diff changeset
1053 plus
kono
parents:
diff changeset
1054 /\
kono
parents:
diff changeset
1055 / \
kono
parents:
diff changeset
1056 plus idx
kono
parents:
diff changeset
1057 /\
kono
parents:
diff changeset
1058 / \
kono
parents:
diff changeset
1059 reg const_int
kono
parents:
diff changeset
1060
kono
parents:
diff changeset
1061 Check if the operand 1 is valid index register. */
kono
parents:
diff changeset
1062 data = ILLEGAL_DM;
kono
parents:
diff changeset
1063 if (debug_print)
kono
parents:
diff changeset
1064 fprintf (stderr, "\ndata:%d", data);
kono
parents:
diff changeset
1065 switch (GET_CODE (XEXP (addr, 1)))
kono
parents:
diff changeset
1066 {
kono
parents:
diff changeset
1067 case REG:
kono
parents:
diff changeset
1068 case SUBREG:
kono
parents:
diff changeset
1069 if (!REG_OK_FOR_INDEX_P (XEXP (addr, 1)))
kono
parents:
diff changeset
1070 return CR16_INVALID;
kono
parents:
diff changeset
1071 /* OK. REG is a valid index register. */
kono
parents:
diff changeset
1072 index = XEXP (addr, 1);
kono
parents:
diff changeset
1073 if (debug_print)
kono
parents:
diff changeset
1074 {
kono
parents:
diff changeset
1075 fprintf (stderr, "\nindex:");
kono
parents:
diff changeset
1076 debug_rtx (index);
kono
parents:
diff changeset
1077 }
kono
parents:
diff changeset
1078 break;
kono
parents:
diff changeset
1079 default:
kono
parents:
diff changeset
1080 return CR16_INVALID;
kono
parents:
diff changeset
1081 }
kono
parents:
diff changeset
1082 /* Check if operand 0 of operand 0 is REGP. */
kono
parents:
diff changeset
1083 switch (GET_CODE (XEXP (XEXP (addr, 0), 0)))
kono
parents:
diff changeset
1084 {
kono
parents:
diff changeset
1085 case REG:
kono
parents:
diff changeset
1086 case SUBREG:
kono
parents:
diff changeset
1087 /* Now check if REG is a REGP and not in LONG regs. */
kono
parents:
diff changeset
1088 if (GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (addr, 0), 0)))
kono
parents:
diff changeset
1089 > BITS_PER_WORD)
kono
parents:
diff changeset
1090 {
kono
parents:
diff changeset
1091 if (REGNO (XEXP (XEXP (addr, 0), 0))
kono
parents:
diff changeset
1092 >= CR16_FIRST_DWORD_REGISTER)
kono
parents:
diff changeset
1093 return CR16_INVALID;
kono
parents:
diff changeset
1094 base = XEXP (XEXP (addr, 0), 0);
kono
parents:
diff changeset
1095 if (debug_print)
kono
parents:
diff changeset
1096 {
kono
parents:
diff changeset
1097 fprintf (stderr, "\nbase:");
kono
parents:
diff changeset
1098 debug_rtx (base);
kono
parents:
diff changeset
1099 }
kono
parents:
diff changeset
1100 }
kono
parents:
diff changeset
1101 else
kono
parents:
diff changeset
1102 return CR16_INVALID;
kono
parents:
diff changeset
1103 break;
kono
parents:
diff changeset
1104 default:
kono
parents:
diff changeset
1105 return CR16_INVALID;
kono
parents:
diff changeset
1106 }
kono
parents:
diff changeset
1107 /* Now check if the operand 1 of operand 0 is const_int. */
kono
parents:
diff changeset
1108 if (GET_CODE (XEXP (XEXP (addr, 0), 1)) == CONST_INT)
kono
parents:
diff changeset
1109 {
kono
parents:
diff changeset
1110 disp = XEXP (XEXP (addr, 0), 1);
kono
parents:
diff changeset
1111 if (debug_print)
kono
parents:
diff changeset
1112 {
kono
parents:
diff changeset
1113 fprintf (stderr, "\ndisp:");
kono
parents:
diff changeset
1114 debug_rtx (disp);
kono
parents:
diff changeset
1115 }
kono
parents:
diff changeset
1116 if (!UNSIGNED_INT_FITS_N_BITS (INTVAL (disp), 20))
kono
parents:
diff changeset
1117 return CR16_INVALID;
kono
parents:
diff changeset
1118 }
kono
parents:
diff changeset
1119 else
kono
parents:
diff changeset
1120 return CR16_INVALID;
kono
parents:
diff changeset
1121 retval = CR16_INDEX_REGP_REL;
kono
parents:
diff changeset
1122 break;
kono
parents:
diff changeset
1123 default:
kono
parents:
diff changeset
1124 return CR16_INVALID;
kono
parents:
diff changeset
1125 }
kono
parents:
diff changeset
1126 break;
kono
parents:
diff changeset
1127
kono
parents:
diff changeset
1128 default:
kono
parents:
diff changeset
1129 return CR16_INVALID;
kono
parents:
diff changeset
1130 }
kono
parents:
diff changeset
1131
kono
parents:
diff changeset
1132 /* Check if the base and index registers are valid. */
kono
parents:
diff changeset
1133 if (base && !(cr16_addr_reg_p (base)))
kono
parents:
diff changeset
1134 return CR16_INVALID;
kono
parents:
diff changeset
1135 if (base && !(CR16_REG_OK_FOR_BASE_P (base)))
kono
parents:
diff changeset
1136 return CR16_INVALID;
kono
parents:
diff changeset
1137 if (index && !(REG_OK_FOR_INDEX_P (index)))
kono
parents:
diff changeset
1138 return CR16_INVALID;
kono
parents:
diff changeset
1139
kono
parents:
diff changeset
1140 /* Write the decomposition to out parameter. */
kono
parents:
diff changeset
1141 out->base = base;
kono
parents:
diff changeset
1142 out->disp = disp;
kono
parents:
diff changeset
1143 out->index = index;
kono
parents:
diff changeset
1144 out->data = data;
kono
parents:
diff changeset
1145 out->code = code;
kono
parents:
diff changeset
1146
kono
parents:
diff changeset
1147 return retval;
kono
parents:
diff changeset
1148 }
kono
parents:
diff changeset
1149
kono
parents:
diff changeset
1150 /* Return non-zero value if 'x' is legitimate PIC operand
kono
parents:
diff changeset
1151 when generating PIC code. */
kono
parents:
diff changeset
1152 int
kono
parents:
diff changeset
1153 legitimate_pic_operand_p (rtx x)
kono
parents:
diff changeset
1154 {
kono
parents:
diff changeset
1155 switch (GET_CODE (x))
kono
parents:
diff changeset
1156 {
kono
parents:
diff changeset
1157 case SYMBOL_REF:
kono
parents:
diff changeset
1158 return 0;
kono
parents:
diff changeset
1159 case LABEL_REF:
kono
parents:
diff changeset
1160 return 0;
kono
parents:
diff changeset
1161 case CONST:
kono
parents:
diff changeset
1162 /* REVISIT: Use something like symbol_referenced_p. */
kono
parents:
diff changeset
1163 if (GET_CODE (XEXP (x, 0)) == PLUS
kono
parents:
diff changeset
1164 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
kono
parents:
diff changeset
1165 || GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF)
kono
parents:
diff changeset
1166 && (GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))
kono
parents:
diff changeset
1167 return 0;
kono
parents:
diff changeset
1168 break;
kono
parents:
diff changeset
1169 case MEM:
kono
parents:
diff changeset
1170 return legitimate_pic_operand_p (XEXP (x, 0));
kono
parents:
diff changeset
1171 default:
kono
parents:
diff changeset
1172 break;
kono
parents:
diff changeset
1173 }
kono
parents:
diff changeset
1174 return 1;
kono
parents:
diff changeset
1175 }
kono
parents:
diff changeset
1176
kono
parents:
diff changeset
1177 /* Convert a non-PIC address in `orig' to a PIC address in `reg'.
kono
parents:
diff changeset
1178
kono
parents:
diff changeset
1179 Input Output (-f pic) Output (-f PIC)
kono
parents:
diff changeset
1180 orig reg
kono
parents:
diff changeset
1181
kono
parents:
diff changeset
1182 C1 symbol symbol@BRO (r12) symbol@GOT (r12)
kono
parents:
diff changeset
1183
kono
parents:
diff changeset
1184 C2 symbol + offset symbol+offset@BRO (r12) symbol+offset@GOT (r12)
kono
parents:
diff changeset
1185
kono
parents:
diff changeset
1186 NOTE: @BRO is added using unspec:BRO
kono
parents:
diff changeset
1187 NOTE: @GOT is added using unspec:GOT. */
kono
parents:
diff changeset
1188 rtx
kono
parents:
diff changeset
1189 legitimize_pic_address (rtx orig, machine_mode mode ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
1190 rtx reg)
kono
parents:
diff changeset
1191 {
kono
parents:
diff changeset
1192 /* First handle a simple SYMBOL_REF or LABEL_REF. */
kono
parents:
diff changeset
1193 if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
kono
parents:
diff changeset
1194 {
kono
parents:
diff changeset
1195 if (reg == 0)
kono
parents:
diff changeset
1196 reg = gen_reg_rtx (Pmode);
kono
parents:
diff changeset
1197
kono
parents:
diff changeset
1198 if (flag_pic == NEAR_PIC)
kono
parents:
diff changeset
1199 {
kono
parents:
diff changeset
1200 /* Unspec to handle -fpic option. */
kono
parents:
diff changeset
1201 emit_insn (gen_unspec_bro_addr (reg, orig));
kono
parents:
diff changeset
1202 emit_insn (gen_addsi3 (reg, reg, pic_offset_table_rtx));
kono
parents:
diff changeset
1203 }
kono
parents:
diff changeset
1204 else if (flag_pic == FAR_PIC)
kono
parents:
diff changeset
1205 {
kono
parents:
diff changeset
1206 /* Unspec to handle -fPIC option. */
kono
parents:
diff changeset
1207 emit_insn (gen_unspec_got_addr (reg, orig));
kono
parents:
diff changeset
1208 }
kono
parents:
diff changeset
1209 return reg;
kono
parents:
diff changeset
1210 }
kono
parents:
diff changeset
1211 else if (GET_CODE (orig) == CONST)
kono
parents:
diff changeset
1212 {
kono
parents:
diff changeset
1213 /* To handle (symbol + offset). */
kono
parents:
diff changeset
1214 rtx base, offset;
kono
parents:
diff changeset
1215
kono
parents:
diff changeset
1216 if (GET_CODE (XEXP (orig, 0)) == PLUS
kono
parents:
diff changeset
1217 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
kono
parents:
diff changeset
1218 return orig;
kono
parents:
diff changeset
1219
kono
parents:
diff changeset
1220 if (reg == 0)
kono
parents:
diff changeset
1221 {
kono
parents:
diff changeset
1222 gcc_assert (can_create_pseudo_p ());
kono
parents:
diff changeset
1223 reg = gen_reg_rtx (Pmode);
kono
parents:
diff changeset
1224 }
kono
parents:
diff changeset
1225
kono
parents:
diff changeset
1226 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
kono
parents:
diff changeset
1227
kono
parents:
diff changeset
1228 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
kono
parents:
diff changeset
1229 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
kono
parents:
diff changeset
1230 base == reg ? 0 : reg);
kono
parents:
diff changeset
1231
kono
parents:
diff changeset
1232 /* REVISIT: Optimize for const-offsets. */
kono
parents:
diff changeset
1233 emit_insn (gen_addsi3 (reg, base, offset));
kono
parents:
diff changeset
1234
kono
parents:
diff changeset
1235 return reg;
kono
parents:
diff changeset
1236 }
kono
parents:
diff changeset
1237 return orig;
kono
parents:
diff changeset
1238 }
kono
parents:
diff changeset
1239
kono
parents:
diff changeset
1240 /* Implementation of TARGET_LEGITIMATE_ADDRESS_P. */
kono
parents:
diff changeset
1241 static bool
kono
parents:
diff changeset
1242 cr16_legitimate_address_p (machine_mode mode ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
1243 rtx addr, bool strict)
kono
parents:
diff changeset
1244 {
kono
parents:
diff changeset
1245 enum cr16_addrtype addrtype;
kono
parents:
diff changeset
1246 struct cr16_address address;
kono
parents:
diff changeset
1247
kono
parents:
diff changeset
1248 if (TARGET_DEBUG_ADDR)
kono
parents:
diff changeset
1249 {
kono
parents:
diff changeset
1250 fprintf (stderr,
kono
parents:
diff changeset
1251 "\n======\nTARGET_LEGITIMATE_ADDRESS_P, mode = %s, strict = %d",
kono
parents:
diff changeset
1252 GET_MODE_NAME (mode), strict);
kono
parents:
diff changeset
1253 debug_rtx (addr);
kono
parents:
diff changeset
1254 }
kono
parents:
diff changeset
1255 addrtype = cr16_decompose_address (addr, &address,
kono
parents:
diff changeset
1256 (TARGET_DEBUG_ADDR ? 1 : 0), FALSE);
kono
parents:
diff changeset
1257
kono
parents:
diff changeset
1258 if (TARGET_DEBUG_ADDR)
kono
parents:
diff changeset
1259 {
kono
parents:
diff changeset
1260 const char *typestr;
kono
parents:
diff changeset
1261
kono
parents:
diff changeset
1262 switch (addrtype)
kono
parents:
diff changeset
1263 {
kono
parents:
diff changeset
1264 case CR16_INVALID:
kono
parents:
diff changeset
1265 typestr = "invalid";
kono
parents:
diff changeset
1266 break;
kono
parents:
diff changeset
1267 case CR16_ABSOLUTE:
kono
parents:
diff changeset
1268 typestr = "absolute";
kono
parents:
diff changeset
1269 break;
kono
parents:
diff changeset
1270 case CR16_REG_REL:
kono
parents:
diff changeset
1271 typestr = "register relative";
kono
parents:
diff changeset
1272 break;
kono
parents:
diff changeset
1273 case CR16_REGP_REL:
kono
parents:
diff changeset
1274 typestr = "register pair relative";
kono
parents:
diff changeset
1275 break;
kono
parents:
diff changeset
1276 case CR16_INDEX_REGP_REL:
kono
parents:
diff changeset
1277 typestr = "index + register pair relative";
kono
parents:
diff changeset
1278 break;
kono
parents:
diff changeset
1279 default:
kono
parents:
diff changeset
1280 gcc_unreachable ();
kono
parents:
diff changeset
1281 }
kono
parents:
diff changeset
1282 fprintf (stderr, "\ncr16 address type: %s\n", typestr);
kono
parents:
diff changeset
1283 }
kono
parents:
diff changeset
1284
kono
parents:
diff changeset
1285 if (addrtype == CR16_INVALID)
kono
parents:
diff changeset
1286 return FALSE;
kono
parents:
diff changeset
1287
kono
parents:
diff changeset
1288 if (strict)
kono
parents:
diff changeset
1289 {
kono
parents:
diff changeset
1290 if (address.base
kono
parents:
diff changeset
1291 && !REGNO_MODE_OK_FOR_BASE_P (REGNO (address.base), mode))
kono
parents:
diff changeset
1292 {
kono
parents:
diff changeset
1293 if (TARGET_DEBUG_ADDR)
kono
parents:
diff changeset
1294 fprintf (stderr, "base register not strict\n");
kono
parents:
diff changeset
1295 return FALSE;
kono
parents:
diff changeset
1296 }
kono
parents:
diff changeset
1297 if (address.index && !REGNO_OK_FOR_INDEX_P (REGNO (address.index)))
kono
parents:
diff changeset
1298 {
kono
parents:
diff changeset
1299 if (TARGET_DEBUG_ADDR)
kono
parents:
diff changeset
1300 fprintf (stderr, "index register not strict\n");
kono
parents:
diff changeset
1301 return FALSE;
kono
parents:
diff changeset
1302 }
kono
parents:
diff changeset
1303 }
kono
parents:
diff changeset
1304
kono
parents:
diff changeset
1305 /* Return true if addressing mode is register relative. */
kono
parents:
diff changeset
1306 if (flag_pic)
kono
parents:
diff changeset
1307 {
kono
parents:
diff changeset
1308 if (addrtype == CR16_REG_REL || addrtype == CR16_REGP_REL)
kono
parents:
diff changeset
1309 return TRUE;
kono
parents:
diff changeset
1310 else
kono
parents:
diff changeset
1311 return FALSE;
kono
parents:
diff changeset
1312 }
kono
parents:
diff changeset
1313
kono
parents:
diff changeset
1314 return TRUE;
kono
parents:
diff changeset
1315 }
kono
parents:
diff changeset
1316
kono
parents:
diff changeset
1317 /* Routines to compute costs. */
kono
parents:
diff changeset
1318
kono
parents:
diff changeset
1319 /* Return cost of the memory address x. */
kono
parents:
diff changeset
1320 static int
kono
parents:
diff changeset
1321 cr16_address_cost (rtx addr, machine_mode mode ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
1322 addr_space_t as ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
1323 bool speed ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
1324 {
kono
parents:
diff changeset
1325 enum cr16_addrtype addrtype;
kono
parents:
diff changeset
1326 struct cr16_address address;
kono
parents:
diff changeset
1327 int cost = 2;
kono
parents:
diff changeset
1328
kono
parents:
diff changeset
1329 addrtype = cr16_decompose_address (addr, &address, 0, FALSE);
kono
parents:
diff changeset
1330
kono
parents:
diff changeset
1331 gcc_assert (addrtype != CR16_INVALID);
kono
parents:
diff changeset
1332
kono
parents:
diff changeset
1333 /* CR16_ABSOLUTE : 3
kono
parents:
diff changeset
1334 CR16_REG_REL (disp !=0) : 4
kono
parents:
diff changeset
1335 CR16_REG_REL (disp ==0) : 5
kono
parents:
diff changeset
1336 CR16_REGP_REL (disp !=0) : 6
kono
parents:
diff changeset
1337 CR16_REGP_REL (disp ==0) : 7
kono
parents:
diff changeset
1338 CR16_INDEX_REGP_REL (disp !=0) : 8
kono
parents:
diff changeset
1339 CR16_INDEX_REGP_REL (disp ==0) : 9. */
kono
parents:
diff changeset
1340 switch (addrtype)
kono
parents:
diff changeset
1341 {
kono
parents:
diff changeset
1342 case CR16_ABSOLUTE:
kono
parents:
diff changeset
1343 cost += 1;
kono
parents:
diff changeset
1344 break;
kono
parents:
diff changeset
1345 case CR16_REGP_REL:
kono
parents:
diff changeset
1346 cost += 2;
kono
parents:
diff changeset
1347 /* Fall through. */
kono
parents:
diff changeset
1348 case CR16_REG_REL:
kono
parents:
diff changeset
1349 cost += 3;
kono
parents:
diff changeset
1350 if (address.disp)
kono
parents:
diff changeset
1351 cost -= 1;
kono
parents:
diff changeset
1352 break;
kono
parents:
diff changeset
1353 case CR16_INDEX_REGP_REL:
kono
parents:
diff changeset
1354 cost += 7;
kono
parents:
diff changeset
1355 if (address.disp)
kono
parents:
diff changeset
1356 cost -= 1;
kono
parents:
diff changeset
1357 default:
kono
parents:
diff changeset
1358 break;
kono
parents:
diff changeset
1359 }
kono
parents:
diff changeset
1360
kono
parents:
diff changeset
1361 if (TARGET_DEBUG_ADDR)
kono
parents:
diff changeset
1362 {
kono
parents:
diff changeset
1363 fprintf (stderr, "\n======\nmacro TARGET_ADDRESS_COST = %d\n", cost);
kono
parents:
diff changeset
1364 debug_rtx (addr);
kono
parents:
diff changeset
1365 }
kono
parents:
diff changeset
1366
kono
parents:
diff changeset
1367 return cost;
kono
parents:
diff changeset
1368 }
kono
parents:
diff changeset
1369
kono
parents:
diff changeset
1370
kono
parents:
diff changeset
1371 /* Implement `TARGET_REGISTER_MOVE_COST'. */
kono
parents:
diff changeset
1372 static int
kono
parents:
diff changeset
1373 cr16_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
1374 reg_class_t from ATTRIBUTE_UNUSED, reg_class_t to)
kono
parents:
diff changeset
1375 {
kono
parents:
diff changeset
1376 return (to != GENERAL_REGS ? 8 : 2);
kono
parents:
diff changeset
1377 }
kono
parents:
diff changeset
1378
kono
parents:
diff changeset
1379 /* Implement `TARGET_MEMORY_MOVE_COST'. */
kono
parents:
diff changeset
1380
kono
parents:
diff changeset
1381 /* Return the cost of moving data of mode MODE between a register of class
kono
parents:
diff changeset
1382 CLASS and memory; IN is zero if the value is to be written to memory,
kono
parents:
diff changeset
1383 nonzero if it is to be read in. This cost is relative to those in
kono
parents:
diff changeset
1384 REGISTER_MOVE_COST. */
kono
parents:
diff changeset
1385 static int
kono
parents:
diff changeset
1386 cr16_memory_move_cost (machine_mode mode,
kono
parents:
diff changeset
1387 reg_class_t rclass ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
1388 bool in ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
1389 {
kono
parents:
diff changeset
1390 /* One LD or ST takes twice the time of a simple reg-reg move. */
kono
parents:
diff changeset
1391 if (reg_classes_intersect_p (rclass, GENERAL_REGS))
kono
parents:
diff changeset
1392 return (4 * cr16_hard_regno_nregs (0, mode));
kono
parents:
diff changeset
1393 else
kono
parents:
diff changeset
1394 return (100);
kono
parents:
diff changeset
1395 }
kono
parents:
diff changeset
1396
kono
parents:
diff changeset
1397 /* Instruction output. */
kono
parents:
diff changeset
1398
kono
parents:
diff changeset
1399 /* Check if a const_double is ok for cr16 store-immediate instructions. */
kono
parents:
diff changeset
1400 int
kono
parents:
diff changeset
1401 cr16_const_double_ok (rtx op)
kono
parents:
diff changeset
1402 {
kono
parents:
diff changeset
1403 if (GET_MODE (op) == SFmode)
kono
parents:
diff changeset
1404 {
kono
parents:
diff changeset
1405 long l;
kono
parents:
diff changeset
1406 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (op), l);
kono
parents:
diff changeset
1407 return UNSIGNED_INT_FITS_N_BITS (l, 4) ? 1 : 0;
kono
parents:
diff changeset
1408 }
kono
parents:
diff changeset
1409
kono
parents:
diff changeset
1410 return ((UNSIGNED_INT_FITS_N_BITS (CONST_DOUBLE_LOW (op), 4)) &&
kono
parents:
diff changeset
1411 (UNSIGNED_INT_FITS_N_BITS (CONST_DOUBLE_HIGH (op), 4))) ? 1 : 0;
kono
parents:
diff changeset
1412 }
kono
parents:
diff changeset
1413
kono
parents:
diff changeset
1414 /* Returns bit position of first 0 or 1 bit.
kono
parents:
diff changeset
1415 It is safe to assume val as 16-bit wide. */
kono
parents:
diff changeset
1416 int
kono
parents:
diff changeset
1417 cr16_operand_bit_pos (int val, int bitval)
kono
parents:
diff changeset
1418 {
kono
parents:
diff changeset
1419 int i;
kono
parents:
diff changeset
1420 if (bitval == 0)
kono
parents:
diff changeset
1421 val = ~val;
kono
parents:
diff changeset
1422
kono
parents:
diff changeset
1423 for (i = 0; i < 16; i++)
kono
parents:
diff changeset
1424 if (val & (1 << i))
kono
parents:
diff changeset
1425 break;
kono
parents:
diff changeset
1426 return i;
kono
parents:
diff changeset
1427 }
kono
parents:
diff changeset
1428
kono
parents:
diff changeset
1429 /* Implements the macro PRINT_OPERAND defined in cr16.h. */
kono
parents:
diff changeset
1430 static void
kono
parents:
diff changeset
1431 cr16_print_operand (FILE * file, rtx x, int code)
kono
parents:
diff changeset
1432 {
kono
parents:
diff changeset
1433 int ptr_dereference = 0;
kono
parents:
diff changeset
1434
kono
parents:
diff changeset
1435 switch (code)
kono
parents:
diff changeset
1436 {
kono
parents:
diff changeset
1437 case 'd':
kono
parents:
diff changeset
1438 {
kono
parents:
diff changeset
1439 const char *cr16_cmp_str;
kono
parents:
diff changeset
1440 switch (GET_CODE (x))
kono
parents:
diff changeset
1441 {
kono
parents:
diff changeset
1442 /* MD: compare (reg, reg or imm) but CR16: cmp (reg or imm, reg)
kono
parents:
diff changeset
1443 -> swap all non symmetric ops. */
kono
parents:
diff changeset
1444 case EQ:
kono
parents:
diff changeset
1445 cr16_cmp_str = "eq";
kono
parents:
diff changeset
1446 break;
kono
parents:
diff changeset
1447 case NE:
kono
parents:
diff changeset
1448 cr16_cmp_str = "ne";
kono
parents:
diff changeset
1449 break;
kono
parents:
diff changeset
1450 case GT:
kono
parents:
diff changeset
1451 cr16_cmp_str = "lt";
kono
parents:
diff changeset
1452 break;
kono
parents:
diff changeset
1453 case GTU:
kono
parents:
diff changeset
1454 cr16_cmp_str = "lo";
kono
parents:
diff changeset
1455 break;
kono
parents:
diff changeset
1456 case LT:
kono
parents:
diff changeset
1457 cr16_cmp_str = "gt";
kono
parents:
diff changeset
1458 break;
kono
parents:
diff changeset
1459 case LTU:
kono
parents:
diff changeset
1460 cr16_cmp_str = "hi";
kono
parents:
diff changeset
1461 break;
kono
parents:
diff changeset
1462 case GE:
kono
parents:
diff changeset
1463 cr16_cmp_str = "le";
kono
parents:
diff changeset
1464 break;
kono
parents:
diff changeset
1465 case GEU:
kono
parents:
diff changeset
1466 cr16_cmp_str = "ls";
kono
parents:
diff changeset
1467 break;
kono
parents:
diff changeset
1468 case LE:
kono
parents:
diff changeset
1469 cr16_cmp_str = "ge";
kono
parents:
diff changeset
1470 break;
kono
parents:
diff changeset
1471 case LEU:
kono
parents:
diff changeset
1472 cr16_cmp_str = "hs";
kono
parents:
diff changeset
1473 break;
kono
parents:
diff changeset
1474 default:
kono
parents:
diff changeset
1475 gcc_unreachable ();
kono
parents:
diff changeset
1476 }
kono
parents:
diff changeset
1477 fprintf (file, "%s", cr16_cmp_str);
kono
parents:
diff changeset
1478 return;
kono
parents:
diff changeset
1479 }
kono
parents:
diff changeset
1480 case '$':
kono
parents:
diff changeset
1481 putc ('$', file);
kono
parents:
diff changeset
1482 return;
kono
parents:
diff changeset
1483
kono
parents:
diff changeset
1484 case 'p':
kono
parents:
diff changeset
1485 if (GET_CODE (x) == REG)
kono
parents:
diff changeset
1486 {
kono
parents:
diff changeset
1487 /* For Push instructions, we should not print register pairs. */
kono
parents:
diff changeset
1488 fprintf (file, "%s", reg_names[REGNO (x)]);
kono
parents:
diff changeset
1489 return;
kono
parents:
diff changeset
1490 }
kono
parents:
diff changeset
1491 break;
kono
parents:
diff changeset
1492
kono
parents:
diff changeset
1493 case 'b':
kono
parents:
diff changeset
1494 /* Print the immediate address for bal
kono
parents:
diff changeset
1495 'b' is used instead of 'a' to avoid compiler calling
kono
parents:
diff changeset
1496 the GO_IF_LEGITIMATE_ADDRESS which cannot
kono
parents:
diff changeset
1497 perform checks on const_int code addresses as it
kono
parents:
diff changeset
1498 assumes all const_int are data addresses. */
kono
parents:
diff changeset
1499 fprintf (file, "0x%lx", INTVAL (x));
kono
parents:
diff changeset
1500 return;
kono
parents:
diff changeset
1501
kono
parents:
diff changeset
1502 case 'r':
kono
parents:
diff changeset
1503 /* Print bit position of first 0. */
kono
parents:
diff changeset
1504 fprintf (file, "%d", cr16_operand_bit_pos (INTVAL (x), 0));
kono
parents:
diff changeset
1505 return;
kono
parents:
diff changeset
1506
kono
parents:
diff changeset
1507 case 's':
kono
parents:
diff changeset
1508 /* Print bit position of first 1. */
kono
parents:
diff changeset
1509 fprintf (file, "%d", cr16_operand_bit_pos (INTVAL (x), 1));
kono
parents:
diff changeset
1510 return;
kono
parents:
diff changeset
1511 case 'g':
kono
parents:
diff changeset
1512 /* 'g' is used for implicit mem: dereference. */
kono
parents:
diff changeset
1513 ptr_dereference = 1;
kono
parents:
diff changeset
1514 /* FALLTHRU */
kono
parents:
diff changeset
1515 case 'f':
kono
parents:
diff changeset
1516 case 0:
kono
parents:
diff changeset
1517 /* default. */
kono
parents:
diff changeset
1518 switch (GET_CODE (x))
kono
parents:
diff changeset
1519 {
kono
parents:
diff changeset
1520 case REG:
kono
parents:
diff changeset
1521 if (GET_MODE_BITSIZE (GET_MODE (x)) > BITS_PER_WORD)
kono
parents:
diff changeset
1522 {
kono
parents:
diff changeset
1523 if (LONG_REG_P (REGNO (x)))
kono
parents:
diff changeset
1524 fprintf (file, "(%s)", reg_names[REGNO (x)]);
kono
parents:
diff changeset
1525 else
kono
parents:
diff changeset
1526 fprintf (file, "(%s,%s)", reg_names[REGNO (x) + 1],
kono
parents:
diff changeset
1527 reg_names[REGNO (x)]);
kono
parents:
diff changeset
1528 }
kono
parents:
diff changeset
1529 else
kono
parents:
diff changeset
1530 fprintf (file, "%s", reg_names[REGNO (x)]);
kono
parents:
diff changeset
1531 return;
kono
parents:
diff changeset
1532
kono
parents:
diff changeset
1533 case MEM:
kono
parents:
diff changeset
1534 output_address (GET_MODE (x), XEXP (x, 0));
kono
parents:
diff changeset
1535 return;
kono
parents:
diff changeset
1536
kono
parents:
diff changeset
1537 case CONST_DOUBLE:
kono
parents:
diff changeset
1538 {
kono
parents:
diff changeset
1539 long l;
kono
parents:
diff changeset
1540
kono
parents:
diff changeset
1541 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l);
kono
parents:
diff changeset
1542
kono
parents:
diff changeset
1543 fprintf (file, "$0x%lx", l);
kono
parents:
diff changeset
1544 return;
kono
parents:
diff changeset
1545 }
kono
parents:
diff changeset
1546 case CONST_INT:
kono
parents:
diff changeset
1547 {
kono
parents:
diff changeset
1548 fprintf (file, "$%ld", INTVAL (x));
kono
parents:
diff changeset
1549 return;
kono
parents:
diff changeset
1550 }
kono
parents:
diff changeset
1551 case UNSPEC:
kono
parents:
diff changeset
1552 switch (XINT (x, 1))
kono
parents:
diff changeset
1553 {
kono
parents:
diff changeset
1554 default:
kono
parents:
diff changeset
1555 gcc_unreachable ();
kono
parents:
diff changeset
1556 }
kono
parents:
diff changeset
1557 break;
kono
parents:
diff changeset
1558
kono
parents:
diff changeset
1559 default:
kono
parents:
diff changeset
1560 if (!ptr_dereference)
kono
parents:
diff changeset
1561 {
kono
parents:
diff changeset
1562 putc ('$', file);
kono
parents:
diff changeset
1563 }
kono
parents:
diff changeset
1564 cr16_print_operand_address (file, VOIDmode, x);
kono
parents:
diff changeset
1565 return;
kono
parents:
diff changeset
1566 }
kono
parents:
diff changeset
1567 gcc_unreachable ();
kono
parents:
diff changeset
1568 default:
kono
parents:
diff changeset
1569 output_operand_lossage ("invalid %%xn code");
kono
parents:
diff changeset
1570 }
kono
parents:
diff changeset
1571
kono
parents:
diff changeset
1572 gcc_unreachable ();
kono
parents:
diff changeset
1573 }
kono
parents:
diff changeset
1574
kono
parents:
diff changeset
1575 /* Implements the macro PRINT_OPERAND_ADDRESS defined in cr16.h. */
kono
parents:
diff changeset
1576
kono
parents:
diff changeset
1577 static void
kono
parents:
diff changeset
1578 cr16_print_operand_address (FILE * file, machine_mode /*mode*/, rtx addr)
kono
parents:
diff changeset
1579 {
kono
parents:
diff changeset
1580 enum cr16_addrtype addrtype;
kono
parents:
diff changeset
1581 struct cr16_address address;
kono
parents:
diff changeset
1582
kono
parents:
diff changeset
1583 /* Decompose the address. Also ask it to treat address as constant. */
kono
parents:
diff changeset
1584 addrtype = cr16_decompose_address (addr, &address, 0, TRUE);
kono
parents:
diff changeset
1585
kono
parents:
diff changeset
1586 if (address.disp && GET_CODE (address.disp) == UNSPEC)
kono
parents:
diff changeset
1587 {
kono
parents:
diff changeset
1588 debug_rtx (addr);
kono
parents:
diff changeset
1589 }
kono
parents:
diff changeset
1590
kono
parents:
diff changeset
1591 switch (addrtype)
kono
parents:
diff changeset
1592 {
kono
parents:
diff changeset
1593 case CR16_REG_REL:
kono
parents:
diff changeset
1594 if (address.disp)
kono
parents:
diff changeset
1595 {
kono
parents:
diff changeset
1596 if (GET_CODE (address.disp) == UNSPEC)
kono
parents:
diff changeset
1597 cr16_print_operand (file, address.disp, 0);
kono
parents:
diff changeset
1598 else
kono
parents:
diff changeset
1599 output_addr_const (file, address.disp);
kono
parents:
diff changeset
1600 }
kono
parents:
diff changeset
1601 else
kono
parents:
diff changeset
1602 fprintf (file, "0");
kono
parents:
diff changeset
1603 fprintf (file, "(%s)", reg_names[REGNO (address.base)]);
kono
parents:
diff changeset
1604 break;
kono
parents:
diff changeset
1605
kono
parents:
diff changeset
1606 case CR16_ABSOLUTE:
kono
parents:
diff changeset
1607 if (address.disp)
kono
parents:
diff changeset
1608 output_addr_const (file, address.disp);
kono
parents:
diff changeset
1609 else
kono
parents:
diff changeset
1610 fprintf (file, "0");
kono
parents:
diff changeset
1611 break;
kono
parents:
diff changeset
1612
kono
parents:
diff changeset
1613 case CR16_INDEX_REGP_REL:
kono
parents:
diff changeset
1614 fprintf (file, "[%s]", reg_names[REGNO (address.index)]);
kono
parents:
diff changeset
1615 /* Fall through. */
kono
parents:
diff changeset
1616 case CR16_REGP_REL:
kono
parents:
diff changeset
1617 if (address.disp)
kono
parents:
diff changeset
1618 {
kono
parents:
diff changeset
1619 if (GET_CODE (address.disp) == UNSPEC)
kono
parents:
diff changeset
1620 cr16_print_operand (file, address.disp, 0);
kono
parents:
diff changeset
1621 else
kono
parents:
diff changeset
1622 output_addr_const (file, address.disp);
kono
parents:
diff changeset
1623 }
kono
parents:
diff changeset
1624 else
kono
parents:
diff changeset
1625 fprintf (file, "0");
kono
parents:
diff changeset
1626 fprintf (file, "(%s,%s)", reg_names[REGNO (address.base) + 1],
kono
parents:
diff changeset
1627 reg_names[REGNO (address.base)]);
kono
parents:
diff changeset
1628 break;
kono
parents:
diff changeset
1629 default:
kono
parents:
diff changeset
1630 debug_rtx (addr);
kono
parents:
diff changeset
1631 gcc_unreachable ();
kono
parents:
diff changeset
1632 }
kono
parents:
diff changeset
1633 /* Add qualifiers to the address expression that was just printed. */
kono
parents:
diff changeset
1634 if (flag_pic < NEAR_PIC && address.code == 0)
kono
parents:
diff changeset
1635 {
kono
parents:
diff changeset
1636 if (address.data == DM_FAR)
kono
parents:
diff changeset
1637 /* Addr contains SYMBOL_REF & far data ptr. */
kono
parents:
diff changeset
1638 fprintf (file, "@l");
kono
parents:
diff changeset
1639 else if (address.data == DM_DEFAULT)
kono
parents:
diff changeset
1640 /* Addr contains SYMBOL_REF & medium data ptr. */
kono
parents:
diff changeset
1641 fprintf (file, "@m");
kono
parents:
diff changeset
1642 /* Addr contains SYMBOL_REF & medium data ptr. */
kono
parents:
diff changeset
1643 else if (address.data == DM_NEAR)
kono
parents:
diff changeset
1644 /* Addr contains SYMBOL_REF & near data ptr. */
kono
parents:
diff changeset
1645 fprintf (file, "@s");
kono
parents:
diff changeset
1646 }
kono
parents:
diff changeset
1647 else if (flag_pic == NEAR_PIC
kono
parents:
diff changeset
1648 && (address.code == 0) && (address.data == DM_FAR
kono
parents:
diff changeset
1649 || address.data == DM_DEFAULT
kono
parents:
diff changeset
1650 || address.data == DM_NEAR))
kono
parents:
diff changeset
1651 {
kono
parents:
diff changeset
1652 fprintf (file, "@l");
kono
parents:
diff changeset
1653 }
kono
parents:
diff changeset
1654 else if (flag_pic == NEAR_PIC && address.code == 2)
kono
parents:
diff changeset
1655 {
kono
parents:
diff changeset
1656 fprintf (file, "pic");
kono
parents:
diff changeset
1657 }
kono
parents:
diff changeset
1658 else if (flag_pic == NEAR_PIC && address.code == 1)
kono
parents:
diff changeset
1659 {
kono
parents:
diff changeset
1660 fprintf (file, "@cpic");
kono
parents:
diff changeset
1661 }
kono
parents:
diff changeset
1662
kono
parents:
diff changeset
1663 else if (flag_pic == FAR_PIC && address.code == 2)
kono
parents:
diff changeset
1664 {
kono
parents:
diff changeset
1665 /* REVISIT: cr16 register indirect jump expects a 1-bit right shifted
kono
parents:
diff changeset
1666 address ! GOTc tells assembler this symbol is a text-address
kono
parents:
diff changeset
1667 This needs to be fixed in such a way that this offset is done
kono
parents:
diff changeset
1668 only in the case where an address is being used for indirect jump
kono
parents:
diff changeset
1669 or call. Determining the potential usage of loadd is of course not
kono
parents:
diff changeset
1670 possible always. Eventually, this has to be fixed in the
kono
parents:
diff changeset
1671 processor. */
kono
parents:
diff changeset
1672 fprintf (file, "GOT (%s)", reg_names[PIC_OFFSET_TABLE_REGNUM]);
kono
parents:
diff changeset
1673 }
kono
parents:
diff changeset
1674 else if (flag_pic == FAR_PIC && address.code == 1)
kono
parents:
diff changeset
1675 {
kono
parents:
diff changeset
1676 fprintf (file, "@cGOT (%s)", reg_names[PIC_OFFSET_TABLE_REGNUM]);
kono
parents:
diff changeset
1677 }
kono
parents:
diff changeset
1678
kono
parents:
diff changeset
1679 else if (flag_pic == FAR_PIC &&
kono
parents:
diff changeset
1680 (address.data == DM_FAR || address.data == DM_DEFAULT
kono
parents:
diff changeset
1681 || address.data == DM_NEAR))
kono
parents:
diff changeset
1682 {
kono
parents:
diff changeset
1683 fprintf (file, "@GOT (%s)", reg_names[PIC_OFFSET_TABLE_REGNUM]);
kono
parents:
diff changeset
1684 }
kono
parents:
diff changeset
1685 }
kono
parents:
diff changeset
1686
kono
parents:
diff changeset
1687 /* Machine description helper functions. */
kono
parents:
diff changeset
1688
kono
parents:
diff changeset
1689 /* Called from cr16.md. The return value depends on the parameter push_or_pop:
kono
parents:
diff changeset
1690 When push_or_pop is zero -> string for push instructions of prologue.
kono
parents:
diff changeset
1691 When push_or_pop is nonzero -> string for pop/popret/retx in epilogue.
kono
parents:
diff changeset
1692 Relies on the assumptions:
kono
parents:
diff changeset
1693 1. RA is the last register to be saved.
kono
parents:
diff changeset
1694 2. The maximal value of the counter is MAX_COUNT. */
kono
parents:
diff changeset
1695 char *
kono
parents:
diff changeset
1696 cr16_prepare_push_pop_string (int push_or_pop)
kono
parents:
diff changeset
1697 {
kono
parents:
diff changeset
1698 /* j is the number of registers being saved, takes care that there won't be
kono
parents:
diff changeset
1699 more than 8 in one push/pop instruction. */
kono
parents:
diff changeset
1700
kono
parents:
diff changeset
1701 /* For the register mask string. */
kono
parents:
diff changeset
1702 static char one_inst_str[50];
kono
parents:
diff changeset
1703
kono
parents:
diff changeset
1704 /* i is the index of current_frame_info.save_regs[], going from 0 until
kono
parents:
diff changeset
1705 current_frame_info.last_reg_to_save. */
kono
parents:
diff changeset
1706 int i, start_reg;
kono
parents:
diff changeset
1707 int word_cnt;
kono
parents:
diff changeset
1708 int print_ra;
kono
parents:
diff changeset
1709 char *return_str;
kono
parents:
diff changeset
1710
kono
parents:
diff changeset
1711 /* For reversing on the push instructions if there are more than one. */
kono
parents:
diff changeset
1712 char *temp_str;
kono
parents:
diff changeset
1713
kono
parents:
diff changeset
1714 return_str = (char *) xmalloc (160);
kono
parents:
diff changeset
1715 temp_str = (char *) xmalloc (160);
kono
parents:
diff changeset
1716
kono
parents:
diff changeset
1717 /* Initialize. */
kono
parents:
diff changeset
1718 memset (return_str, 0, 3);
kono
parents:
diff changeset
1719
kono
parents:
diff changeset
1720 i = 0;
kono
parents:
diff changeset
1721 while (i <= current_frame_info.last_reg_to_save)
kono
parents:
diff changeset
1722 {
kono
parents:
diff changeset
1723 /* Prepare mask for one instruction. */
kono
parents:
diff changeset
1724 one_inst_str[0] = 0;
kono
parents:
diff changeset
1725
kono
parents:
diff changeset
1726 /* To count number of words in one instruction. */
kono
parents:
diff changeset
1727 word_cnt = 0;
kono
parents:
diff changeset
1728 start_reg = i;
kono
parents:
diff changeset
1729 print_ra = 0;
kono
parents:
diff changeset
1730 while ((word_cnt < MAX_COUNT)
kono
parents:
diff changeset
1731 && (i <= current_frame_info.last_reg_to_save))
kono
parents:
diff changeset
1732 {
kono
parents:
diff changeset
1733 /* For each non consecutive save register,
kono
parents:
diff changeset
1734 a new instruction shall be generated. */
kono
parents:
diff changeset
1735 if (!current_frame_info.save_regs[i])
kono
parents:
diff changeset
1736 {
kono
parents:
diff changeset
1737 /* Move to next reg and break. */
kono
parents:
diff changeset
1738 ++i;
kono
parents:
diff changeset
1739 break;
kono
parents:
diff changeset
1740 }
kono
parents:
diff changeset
1741
kono
parents:
diff changeset
1742 if (i == RETURN_ADDRESS_REGNUM)
kono
parents:
diff changeset
1743 print_ra = 1;
kono
parents:
diff changeset
1744 else
kono
parents:
diff changeset
1745 {
kono
parents:
diff changeset
1746 /* Check especially if adding 2 does not cross the MAX_COUNT. */
kono
parents:
diff changeset
1747 if ((word_cnt + ((i < CR16_FIRST_DWORD_REGISTER) ? 1 : 2))
kono
parents:
diff changeset
1748 >= MAX_COUNT)
kono
parents:
diff changeset
1749 break;
kono
parents:
diff changeset
1750 /* Increase word count by 2 for long registers except RA. */
kono
parents:
diff changeset
1751 word_cnt += ((i < CR16_FIRST_DWORD_REGISTER) ? 1 : 2);
kono
parents:
diff changeset
1752 }
kono
parents:
diff changeset
1753 ++i;
kono
parents:
diff changeset
1754 }
kono
parents:
diff changeset
1755
kono
parents:
diff changeset
1756 /* No need to generate any instruction as
kono
parents:
diff changeset
1757 no register or RA needs to be saved. */
kono
parents:
diff changeset
1758 if ((word_cnt == 0) && (print_ra == 0))
kono
parents:
diff changeset
1759 continue;
kono
parents:
diff changeset
1760
kono
parents:
diff changeset
1761 /* Now prepare the instruction operands. */
kono
parents:
diff changeset
1762 if (word_cnt > 0)
kono
parents:
diff changeset
1763 {
kono
parents:
diff changeset
1764 sprintf (one_inst_str, "$%d, %s", word_cnt, reg_names[start_reg]);
kono
parents:
diff changeset
1765 if (print_ra)
kono
parents:
diff changeset
1766 strcat (one_inst_str, ", ra");
kono
parents:
diff changeset
1767 }
kono
parents:
diff changeset
1768 else
kono
parents:
diff changeset
1769 strcat (one_inst_str, "ra");
kono
parents:
diff changeset
1770
kono
parents:
diff changeset
1771 if (push_or_pop == 1)
kono
parents:
diff changeset
1772 {
kono
parents:
diff changeset
1773 /* Pop instruction. */
kono
parents:
diff changeset
1774 if (print_ra && !cr16_interrupt_function_p ()
kono
parents:
diff changeset
1775 && !crtl->calls_eh_return)
kono
parents:
diff changeset
1776 /* Print popret if RA is saved and its not a interrupt
kono
parents:
diff changeset
1777 function. */
kono
parents:
diff changeset
1778 strcpy (temp_str, "\n\tpopret\t");
kono
parents:
diff changeset
1779 else
kono
parents:
diff changeset
1780 strcpy (temp_str, "\n\tpop\t");
kono
parents:
diff changeset
1781
kono
parents:
diff changeset
1782 strcat (temp_str, one_inst_str);
kono
parents:
diff changeset
1783
kono
parents:
diff changeset
1784 /* Add the pop instruction list. */
kono
parents:
diff changeset
1785 strcat (return_str, temp_str);
kono
parents:
diff changeset
1786 }
kono
parents:
diff changeset
1787 else
kono
parents:
diff changeset
1788 {
kono
parents:
diff changeset
1789 /* Push instruction. */
kono
parents:
diff changeset
1790 strcpy (temp_str, "\n\tpush\t");
kono
parents:
diff changeset
1791 strcat (temp_str, one_inst_str);
kono
parents:
diff changeset
1792
kono
parents:
diff changeset
1793 /* We need to reverse the order of the instructions if there
kono
parents:
diff changeset
1794 are more than one. (since the pop will not be reversed in
kono
parents:
diff changeset
1795 the epilogue. */
kono
parents:
diff changeset
1796 strcat (temp_str, return_str);
kono
parents:
diff changeset
1797 strcpy (return_str, temp_str);
kono
parents:
diff changeset
1798 }
kono
parents:
diff changeset
1799 }
kono
parents:
diff changeset
1800
kono
parents:
diff changeset
1801 if (push_or_pop == 1)
kono
parents:
diff changeset
1802 {
kono
parents:
diff changeset
1803 /* POP. */
kono
parents:
diff changeset
1804 if (cr16_interrupt_function_p ())
kono
parents:
diff changeset
1805 strcat (return_str, "\n\tretx\n");
kono
parents:
diff changeset
1806 else if (crtl->calls_eh_return)
kono
parents:
diff changeset
1807 {
kono
parents:
diff changeset
1808 /* Add stack adjustment before returning to exception handler
kono
parents:
diff changeset
1809 NOTE: EH_RETURN_STACKADJ_RTX must refer to (r5, r4). */
kono
parents:
diff changeset
1810 strcat (return_str, "\n\taddd\t (r5, r4), (sp)\t\n");
kono
parents:
diff changeset
1811 strcat (return_str, "\n\tjump\t (ra)\n");
kono
parents:
diff changeset
1812
kono
parents:
diff changeset
1813 /* But before anything else, undo the adjustment addition done in
kono
parents:
diff changeset
1814 cr16_expand_epilogue (). */
kono
parents:
diff changeset
1815 strcpy (temp_str, "\n\tsubd\t (r5, r4), (sp)\t\n");
kono
parents:
diff changeset
1816 strcat (temp_str, return_str);
kono
parents:
diff changeset
1817 strcpy (return_str, temp_str);
kono
parents:
diff changeset
1818 }
kono
parents:
diff changeset
1819 else if (!FUNC_IS_NORETURN_P (current_function_decl)
kono
parents:
diff changeset
1820 && !(current_frame_info.save_regs[RETURN_ADDRESS_REGNUM]))
kono
parents:
diff changeset
1821 strcat (return_str, "\n\tjump\t (ra)\n");
kono
parents:
diff changeset
1822 }
kono
parents:
diff changeset
1823
kono
parents:
diff changeset
1824 /* Skip the newline and the tab in the start of return_str. */
kono
parents:
diff changeset
1825 return_str += 2;
kono
parents:
diff changeset
1826 return return_str;
kono
parents:
diff changeset
1827 }
kono
parents:
diff changeset
1828
kono
parents:
diff changeset
1829
kono
parents:
diff changeset
1830 /* Generate DWARF2 annotation for multi-push instruction. */
kono
parents:
diff changeset
1831 static void
kono
parents:
diff changeset
1832 cr16_create_dwarf_for_multi_push (rtx insn)
kono
parents:
diff changeset
1833 {
kono
parents:
diff changeset
1834 rtx dwarf, reg, tmp;
kono
parents:
diff changeset
1835 int i, j, from, to, word_cnt, dwarf_par_index, inc;
kono
parents:
diff changeset
1836 machine_mode mode;
kono
parents:
diff changeset
1837 int num_regs = 0, offset = 0, split_here = 0, total_push_bytes = 0;
kono
parents:
diff changeset
1838
kono
parents:
diff changeset
1839 for (i = 0; i <= current_frame_info.last_reg_to_save; ++i)
kono
parents:
diff changeset
1840 {
kono
parents:
diff changeset
1841 if (current_frame_info.save_regs[i])
kono
parents:
diff changeset
1842 {
kono
parents:
diff changeset
1843 ++num_regs;
kono
parents:
diff changeset
1844 if (i < CR16_FIRST_DWORD_REGISTER)
kono
parents:
diff changeset
1845 total_push_bytes += 2;
kono
parents:
diff changeset
1846 else
kono
parents:
diff changeset
1847 total_push_bytes += 4;
kono
parents:
diff changeset
1848 }
kono
parents:
diff changeset
1849 }
kono
parents:
diff changeset
1850
kono
parents:
diff changeset
1851 if (!num_regs)
kono
parents:
diff changeset
1852 return;
kono
parents:
diff changeset
1853
kono
parents:
diff changeset
1854 dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (num_regs + 1));
kono
parents:
diff changeset
1855 dwarf_par_index = num_regs;
kono
parents:
diff changeset
1856
kono
parents:
diff changeset
1857 from = current_frame_info.last_reg_to_save + 1;
kono
parents:
diff changeset
1858 to = current_frame_info.last_reg_to_save;
kono
parents:
diff changeset
1859 word_cnt = 0;
kono
parents:
diff changeset
1860
kono
parents:
diff changeset
1861 for (i = current_frame_info.last_reg_to_save; i >= 0;)
kono
parents:
diff changeset
1862 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1863 if (!current_frame_info.save_regs[i] || i == 0 || split_here)
111
kono
parents:
diff changeset
1864 {
kono
parents:
diff changeset
1865 /* This block of regs is pushed in one instruction. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1866 if (i == 0 && current_frame_info.save_regs[i])
111
kono
parents:
diff changeset
1867 from = 0;
kono
parents:
diff changeset
1868
kono
parents:
diff changeset
1869 for (j = to; j >= from; --j)
kono
parents:
diff changeset
1870 {
kono
parents:
diff changeset
1871 if (j < CR16_FIRST_DWORD_REGISTER)
kono
parents:
diff changeset
1872 {
kono
parents:
diff changeset
1873 mode = HImode;
kono
parents:
diff changeset
1874 inc = 1;
kono
parents:
diff changeset
1875 }
kono
parents:
diff changeset
1876 else
kono
parents:
diff changeset
1877 {
kono
parents:
diff changeset
1878 mode = SImode;
kono
parents:
diff changeset
1879 inc = 2;
kono
parents:
diff changeset
1880 }
kono
parents:
diff changeset
1881 reg = gen_rtx_REG (mode, j);
kono
parents:
diff changeset
1882 offset += 2 * inc;
kono
parents:
diff changeset
1883 tmp = gen_rtx_SET (gen_frame_mem (mode,
kono
parents:
diff changeset
1884 plus_constant
kono
parents:
diff changeset
1885 (Pmode, stack_pointer_rtx,
kono
parents:
diff changeset
1886 total_push_bytes - offset)),
kono
parents:
diff changeset
1887 reg);
kono
parents:
diff changeset
1888 RTX_FRAME_RELATED_P (tmp) = 1;
kono
parents:
diff changeset
1889 XVECEXP (dwarf, 0, dwarf_par_index--) = tmp;
kono
parents:
diff changeset
1890 }
kono
parents:
diff changeset
1891 from = i;
kono
parents:
diff changeset
1892 to = --i;
kono
parents:
diff changeset
1893 split_here = 0;
kono
parents:
diff changeset
1894 word_cnt = 0;
kono
parents:
diff changeset
1895 continue;
kono
parents:
diff changeset
1896 }
kono
parents:
diff changeset
1897
kono
parents:
diff changeset
1898 if (i != RETURN_ADDRESS_REGNUM)
kono
parents:
diff changeset
1899 {
kono
parents:
diff changeset
1900 inc = (i < CR16_FIRST_DWORD_REGISTER) ? 1 : 2;
kono
parents:
diff changeset
1901 if (word_cnt + inc >= MAX_COUNT || FRAME_POINTER_REGNUM == i)
kono
parents:
diff changeset
1902 {
kono
parents:
diff changeset
1903 split_here = 1;
kono
parents:
diff changeset
1904 from = i;
kono
parents:
diff changeset
1905 continue;
kono
parents:
diff changeset
1906 }
kono
parents:
diff changeset
1907 word_cnt += inc;
kono
parents:
diff changeset
1908 }
kono
parents:
diff changeset
1909
kono
parents:
diff changeset
1910 from = i--;
kono
parents:
diff changeset
1911 }
kono
parents:
diff changeset
1912
kono
parents:
diff changeset
1913 tmp = gen_rtx_SET (stack_pointer_rtx,
kono
parents:
diff changeset
1914 gen_rtx_PLUS (SImode, stack_pointer_rtx,
kono
parents:
diff changeset
1915 GEN_INT (-offset)));
kono
parents:
diff changeset
1916 RTX_FRAME_RELATED_P (tmp) = 1;
kono
parents:
diff changeset
1917 XVECEXP (dwarf, 0, 0) = tmp;
kono
parents:
diff changeset
1918
kono
parents:
diff changeset
1919 add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf);
kono
parents:
diff changeset
1920 }
kono
parents:
diff changeset
1921
kono
parents:
diff changeset
1922 /*
kono
parents:
diff changeset
1923 CompactRISC CR16 Architecture stack layout:
kono
parents:
diff changeset
1924
kono
parents:
diff changeset
1925 0 +---------------------
kono
parents:
diff changeset
1926 |
kono
parents:
diff changeset
1927 .
kono
parents:
diff changeset
1928 .
kono
parents:
diff changeset
1929 |
kono
parents:
diff changeset
1930 +==================== Sp (x) = Ap (x+1)
kono
parents:
diff changeset
1931 A | Args for functions
kono
parents:
diff changeset
1932 | | called by X and Dynamically
kono
parents:
diff changeset
1933 | | Dynamic allocations allocated and
kono
parents:
diff changeset
1934 | | (alloca, variable deallocated
kono
parents:
diff changeset
1935 Stack | length arrays).
kono
parents:
diff changeset
1936 grows +-------------------- Fp (x)
kono
parents:
diff changeset
1937 down| | Local variables of X
kono
parents:
diff changeset
1938 ward| +--------------------
kono
parents:
diff changeset
1939 | | Regs saved for X-1
kono
parents:
diff changeset
1940 | +==================== Sp (x-1) = Ap (x)
kono
parents:
diff changeset
1941 | Args for func X
kono
parents:
diff changeset
1942 | pushed by X-1
kono
parents:
diff changeset
1943 +-------------------- Fp (x-1)
kono
parents:
diff changeset
1944 |
kono
parents:
diff changeset
1945 |
kono
parents:
diff changeset
1946 V
kono
parents:
diff changeset
1947 */
kono
parents:
diff changeset
1948 void
kono
parents:
diff changeset
1949 cr16_expand_prologue (void)
kono
parents:
diff changeset
1950 {
kono
parents:
diff changeset
1951 rtx insn;
kono
parents:
diff changeset
1952
kono
parents:
diff changeset
1953 cr16_compute_frame ();
kono
parents:
diff changeset
1954 cr16_compute_save_regs ();
kono
parents:
diff changeset
1955
kono
parents:
diff changeset
1956 /* If there is no need in push and adjustment to sp, return. */
kono
parents:
diff changeset
1957 if ((current_frame_info.total_size + current_frame_info.reg_size) == 0)
kono
parents:
diff changeset
1958 return;
kono
parents:
diff changeset
1959
kono
parents:
diff changeset
1960 if (current_frame_info.last_reg_to_save != -1)
kono
parents:
diff changeset
1961 {
kono
parents:
diff changeset
1962 /* If there are registers to push. */
kono
parents:
diff changeset
1963 insn = emit_insn (gen_push_for_prologue
kono
parents:
diff changeset
1964 (GEN_INT (current_frame_info.reg_size)));
kono
parents:
diff changeset
1965 cr16_create_dwarf_for_multi_push (insn);
kono
parents:
diff changeset
1966 RTX_FRAME_RELATED_P (insn) = 1;
kono
parents:
diff changeset
1967 }
kono
parents:
diff changeset
1968
kono
parents:
diff changeset
1969
kono
parents:
diff changeset
1970 if (current_frame_info.total_size > 0)
kono
parents:
diff changeset
1971 {
kono
parents:
diff changeset
1972 insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
kono
parents:
diff changeset
1973 GEN_INT (-current_frame_info.total_size)));
kono
parents:
diff changeset
1974 RTX_FRAME_RELATED_P (insn) = 1;
kono
parents:
diff changeset
1975 }
kono
parents:
diff changeset
1976
kono
parents:
diff changeset
1977 if (frame_pointer_needed)
kono
parents:
diff changeset
1978 {
kono
parents:
diff changeset
1979 /* Initialize the frame pointer with the value of the stack pointer
kono
parents:
diff changeset
1980 pointing now to the locals. */
kono
parents:
diff changeset
1981 insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
kono
parents:
diff changeset
1982 }
kono
parents:
diff changeset
1983 }
kono
parents:
diff changeset
1984
kono
parents:
diff changeset
1985 /* Generate insn that updates the stack for local variables and padding
kono
parents:
diff changeset
1986 for registers we save. - Generate the appropriate return insn. */
kono
parents:
diff changeset
1987 void
kono
parents:
diff changeset
1988 cr16_expand_epilogue (void)
kono
parents:
diff changeset
1989 {
kono
parents:
diff changeset
1990 rtx insn;
kono
parents:
diff changeset
1991
kono
parents:
diff changeset
1992 /* Nonzero if we need to return and pop only RA. This will generate a
kono
parents:
diff changeset
1993 different insn. This differentiate is for the peepholes for call as
kono
parents:
diff changeset
1994 last statement in function. */
kono
parents:
diff changeset
1995 int only_popret_RA = (current_frame_info.save_regs[RETURN_ADDRESS_REGNUM]
kono
parents:
diff changeset
1996 && (current_frame_info.reg_size
kono
parents:
diff changeset
1997 == CR16_UNITS_PER_DWORD));
kono
parents:
diff changeset
1998
kono
parents:
diff changeset
1999 if (frame_pointer_needed)
kono
parents:
diff changeset
2000 {
kono
parents:
diff changeset
2001 /* Restore the stack pointer with the frame pointers value. */
kono
parents:
diff changeset
2002 insn = emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
kono
parents:
diff changeset
2003 }
kono
parents:
diff changeset
2004
kono
parents:
diff changeset
2005 if (current_frame_info.total_size > 0)
kono
parents:
diff changeset
2006 {
kono
parents:
diff changeset
2007 insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
kono
parents:
diff changeset
2008 GEN_INT (current_frame_info.total_size)));
kono
parents:
diff changeset
2009 RTX_FRAME_RELATED_P (insn) = 1;
kono
parents:
diff changeset
2010 }
kono
parents:
diff changeset
2011
kono
parents:
diff changeset
2012 if (crtl->calls_eh_return)
kono
parents:
diff changeset
2013 {
kono
parents:
diff changeset
2014 /* Add this here so that (r5, r4) is actually loaded with the adjustment
kono
parents:
diff changeset
2015 value; otherwise, the load might be optimized away...
kono
parents:
diff changeset
2016 NOTE: remember to subtract the adjustment before popping the regs
kono
parents:
diff changeset
2017 and add it back before returning. */
kono
parents:
diff changeset
2018 insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
kono
parents:
diff changeset
2019 EH_RETURN_STACKADJ_RTX));
kono
parents:
diff changeset
2020 }
kono
parents:
diff changeset
2021
kono
parents:
diff changeset
2022 if (cr16_interrupt_function_p ())
kono
parents:
diff changeset
2023 {
kono
parents:
diff changeset
2024 insn = emit_jump_insn (gen_interrupt_return ());
kono
parents:
diff changeset
2025 RTX_FRAME_RELATED_P (insn) = 1;
kono
parents:
diff changeset
2026 }
kono
parents:
diff changeset
2027 else if (crtl->calls_eh_return)
kono
parents:
diff changeset
2028 {
kono
parents:
diff changeset
2029 /* Special case, pop what's necessary, adjust SP and jump to (RA). */
kono
parents:
diff changeset
2030 insn = emit_jump_insn (gen_pop_and_popret_return
kono
parents:
diff changeset
2031 (GEN_INT (current_frame_info.reg_size)));
kono
parents:
diff changeset
2032 RTX_FRAME_RELATED_P (insn) = 1;
kono
parents:
diff changeset
2033 }
kono
parents:
diff changeset
2034 else if (current_frame_info.last_reg_to_save == -1)
kono
parents:
diff changeset
2035 /* Nothing to pop. */
kono
parents:
diff changeset
2036 /* Don't output jump for interrupt routine, only retx. */
kono
parents:
diff changeset
2037 emit_jump_insn (gen_jump_return ());
kono
parents:
diff changeset
2038 else if (only_popret_RA)
kono
parents:
diff changeset
2039 {
kono
parents:
diff changeset
2040 insn = emit_jump_insn (gen_popret_RA_return ());
kono
parents:
diff changeset
2041 RTX_FRAME_RELATED_P (insn) = 1;
kono
parents:
diff changeset
2042 }
kono
parents:
diff changeset
2043 else
kono
parents:
diff changeset
2044 {
kono
parents:
diff changeset
2045 insn = emit_jump_insn (gen_pop_and_popret_return
kono
parents:
diff changeset
2046 (GEN_INT (current_frame_info.reg_size)));
kono
parents:
diff changeset
2047 RTX_FRAME_RELATED_P (insn) = 1;
kono
parents:
diff changeset
2048 }
kono
parents:
diff changeset
2049 }
kono
parents:
diff changeset
2050
kono
parents:
diff changeset
2051 /* Implements FRAME_POINTER_REQUIRED. */
kono
parents:
diff changeset
2052 static bool
kono
parents:
diff changeset
2053 cr16_frame_pointer_required (void)
kono
parents:
diff changeset
2054 {
kono
parents:
diff changeset
2055 return (cfun->calls_alloca || crtl->calls_eh_return
kono
parents:
diff changeset
2056 || cfun->has_nonlocal_label || crtl->calls_eh_return);
kono
parents:
diff changeset
2057 }
kono
parents:
diff changeset
2058
kono
parents:
diff changeset
2059 static bool
kono
parents:
diff changeset
2060 cr16_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
kono
parents:
diff changeset
2061 {
kono
parents:
diff changeset
2062 return (to == STACK_POINTER_REGNUM ? !frame_pointer_needed : true);
kono
parents:
diff changeset
2063 }
kono
parents:
diff changeset
2064
kono
parents:
diff changeset
2065
kono
parents:
diff changeset
2066 /* A C compound statement that attempts to replace X with
kono
parents:
diff changeset
2067 a valid memory address for an operand of mode MODE. WIN
kono
parents:
diff changeset
2068 will be a C statement label elsewhere in the code.
kono
parents:
diff changeset
2069 X will always be the result of a call to break_out_memory_refs (),
kono
parents:
diff changeset
2070 and OLDX will be the operand that was given to that function to
kono
parents:
diff changeset
2071 produce X.
kono
parents:
diff changeset
2072 The code generated by this macro should not alter the
kono
parents:
diff changeset
2073 substructure of X. If it transforms X into a more legitimate form,
kono
parents:
diff changeset
2074 it should assign X (which will always be a C variable) a new value. */
kono
parents:
diff changeset
2075 static rtx
kono
parents:
diff changeset
2076 cr16_legitimize_address (rtx x, rtx orig_x ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
2077 machine_mode mode ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
2078 {
kono
parents:
diff changeset
2079 if (flag_pic)
kono
parents:
diff changeset
2080 return legitimize_pic_address (orig_x, mode, NULL_RTX);
kono
parents:
diff changeset
2081 else
kono
parents:
diff changeset
2082 return x;
kono
parents:
diff changeset
2083 }
kono
parents:
diff changeset
2084
kono
parents:
diff changeset
2085 /* Implement TARGET_LEGITIMATE_CONSTANT_P
kono
parents:
diff changeset
2086 Nonzero if X is a legitimate constant for an immediate
kono
parents:
diff changeset
2087 operand on the target machine. You can assume that X
kono
parents:
diff changeset
2088 satisfies CONSTANT_P. In cr16c treat legitimize float
kono
parents:
diff changeset
2089 constant as an immediate operand. */
kono
parents:
diff changeset
2090 static bool
kono
parents:
diff changeset
2091 cr16_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
2092 rtx x ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
2093 {
kono
parents:
diff changeset
2094 return 1;
kono
parents:
diff changeset
2095 }
kono
parents:
diff changeset
2096
kono
parents:
diff changeset
2097 void
kono
parents:
diff changeset
2098 notice_update_cc (rtx exp)
kono
parents:
diff changeset
2099 {
kono
parents:
diff changeset
2100 if (GET_CODE (exp) == SET)
kono
parents:
diff changeset
2101 {
kono
parents:
diff changeset
2102 /* Jumps do not alter the cc's. */
kono
parents:
diff changeset
2103 if (SET_DEST (exp) == pc_rtx)
kono
parents:
diff changeset
2104 return;
kono
parents:
diff changeset
2105
kono
parents:
diff changeset
2106 /* Moving register or memory into a register:
kono
parents:
diff changeset
2107 it doesn't alter the cc's, but it might invalidate
kono
parents:
diff changeset
2108 the RTX's which we remember the cc's came from.
kono
parents:
diff changeset
2109 (Note that moving a constant 0 or 1 MAY set the cc's). */
kono
parents:
diff changeset
2110 if (REG_P (SET_DEST (exp))
kono
parents:
diff changeset
2111 && (REG_P (SET_SRC (exp)) || GET_CODE (SET_SRC (exp)) == MEM))
kono
parents:
diff changeset
2112 {
kono
parents:
diff changeset
2113 return;
kono
parents:
diff changeset
2114 }
kono
parents:
diff changeset
2115
kono
parents:
diff changeset
2116 /* Moving register into memory doesn't alter the cc's.
kono
parents:
diff changeset
2117 It may invalidate the RTX's which we remember the cc's came from. */
kono
parents:
diff changeset
2118 if (GET_CODE (SET_DEST (exp)) == MEM && REG_P (SET_SRC (exp)))
kono
parents:
diff changeset
2119 {
kono
parents:
diff changeset
2120 return;
kono
parents:
diff changeset
2121 }
kono
parents:
diff changeset
2122 }
kono
parents:
diff changeset
2123
kono
parents:
diff changeset
2124 CC_STATUS_INIT;
kono
parents:
diff changeset
2125 return;
kono
parents:
diff changeset
2126 }
kono
parents:
diff changeset
2127
kono
parents:
diff changeset
2128 static scalar_int_mode
kono
parents:
diff changeset
2129 cr16_unwind_word_mode (void)
kono
parents:
diff changeset
2130 {
kono
parents:
diff changeset
2131 return SImode;
kono
parents:
diff changeset
2132 }
kono
parents:
diff changeset
2133
kono
parents:
diff changeset
2134 /* Helper function for md file. This function is used to emit arithmetic
kono
parents:
diff changeset
2135 DI instructions. The argument "num" decides which instruction to be
kono
parents:
diff changeset
2136 printed. */
kono
parents:
diff changeset
2137 const char *
kono
parents:
diff changeset
2138 cr16_emit_add_sub_di (rtx *operands, enum rtx_code code)
kono
parents:
diff changeset
2139 {
kono
parents:
diff changeset
2140 rtx lo_op[2] ;
kono
parents:
diff changeset
2141 rtx hi0_op[2] ;
kono
parents:
diff changeset
2142 rtx hi1_op[2] ;
kono
parents:
diff changeset
2143
kono
parents:
diff changeset
2144 lo_op[0] = gen_lowpart (SImode, operands[0]);
kono
parents:
diff changeset
2145 hi0_op[0] = simplify_gen_subreg (HImode, operands[0], DImode, 4);
kono
parents:
diff changeset
2146 hi1_op[0] = simplify_gen_subreg (HImode, operands[0], DImode, 6);
kono
parents:
diff changeset
2147
kono
parents:
diff changeset
2148 lo_op[1] = gen_lowpart (SImode, operands[2]);
kono
parents:
diff changeset
2149 hi0_op[1] = simplify_gen_subreg (HImode, operands[2], DImode, 4);
kono
parents:
diff changeset
2150 hi1_op[1] = simplify_gen_subreg (HImode, operands[2], DImode, 6);
kono
parents:
diff changeset
2151
kono
parents:
diff changeset
2152 switch (code)
kono
parents:
diff changeset
2153 {
kono
parents:
diff changeset
2154 case PLUS:
kono
parents:
diff changeset
2155 {
kono
parents:
diff changeset
2156 output_asm_insn ("addd\t%1, %0", lo_op) ;
kono
parents:
diff changeset
2157 output_asm_insn ("addcw\t%1, %0", hi0_op) ;
kono
parents:
diff changeset
2158 output_asm_insn ("addcw\t%1, %0", hi1_op) ;
kono
parents:
diff changeset
2159 break;
kono
parents:
diff changeset
2160 }
kono
parents:
diff changeset
2161 case MINUS:
kono
parents:
diff changeset
2162 {
kono
parents:
diff changeset
2163 output_asm_insn ("subd\t%1, %0", lo_op) ;
kono
parents:
diff changeset
2164 output_asm_insn ("subcw\t%1, %0", hi0_op) ;
kono
parents:
diff changeset
2165 output_asm_insn ("subcw\t%1, %0", hi1_op) ;
kono
parents:
diff changeset
2166 break;
kono
parents:
diff changeset
2167 }
kono
parents:
diff changeset
2168 default:
kono
parents:
diff changeset
2169 break;
kono
parents:
diff changeset
2170 }
kono
parents:
diff changeset
2171
kono
parents:
diff changeset
2172 return "";
kono
parents:
diff changeset
2173 }
kono
parents:
diff changeset
2174
kono
parents:
diff changeset
2175
kono
parents:
diff changeset
2176 /* Helper function for md file. This function is used to emit logical
kono
parents:
diff changeset
2177 DI instructions. The argument "num" decides which instruction to be
kono
parents:
diff changeset
2178 printed. */
kono
parents:
diff changeset
2179 const char *
kono
parents:
diff changeset
2180 cr16_emit_logical_di (rtx *operands, enum rtx_code code)
kono
parents:
diff changeset
2181 {
kono
parents:
diff changeset
2182 rtx lo_op[2] ;
kono
parents:
diff changeset
2183 rtx hi_op[2] ;
kono
parents:
diff changeset
2184
kono
parents:
diff changeset
2185 lo_op[0] = gen_lowpart (SImode, operands[0]);
kono
parents:
diff changeset
2186 hi_op[0] = simplify_gen_subreg (SImode, operands[0], DImode, 4);
kono
parents:
diff changeset
2187
kono
parents:
diff changeset
2188 lo_op[1] = gen_lowpart (SImode, operands[2]);
kono
parents:
diff changeset
2189 hi_op[1] = simplify_gen_subreg (SImode, operands[2], DImode, 4);
kono
parents:
diff changeset
2190
kono
parents:
diff changeset
2191 switch (code)
kono
parents:
diff changeset
2192 {
kono
parents:
diff changeset
2193 case AND:
kono
parents:
diff changeset
2194 {
kono
parents:
diff changeset
2195 output_asm_insn ("andd\t%1, %0", lo_op) ;
kono
parents:
diff changeset
2196 output_asm_insn ("andd\t%1, %0", hi_op) ;
kono
parents:
diff changeset
2197 return "";
kono
parents:
diff changeset
2198 }
kono
parents:
diff changeset
2199 case IOR:
kono
parents:
diff changeset
2200 {
kono
parents:
diff changeset
2201 output_asm_insn ("ord\t%1, %0", lo_op) ;
kono
parents:
diff changeset
2202 output_asm_insn ("ord\t%1, %0", hi_op) ;
kono
parents:
diff changeset
2203 return "";
kono
parents:
diff changeset
2204 }
kono
parents:
diff changeset
2205 case XOR:
kono
parents:
diff changeset
2206 {
kono
parents:
diff changeset
2207 output_asm_insn ("xord\t%1, %0", lo_op) ;
kono
parents:
diff changeset
2208 output_asm_insn ("xord\t%1, %0", hi_op) ;
kono
parents:
diff changeset
2209 return "";
kono
parents:
diff changeset
2210 }
kono
parents:
diff changeset
2211 default:
kono
parents:
diff changeset
2212 break;
kono
parents:
diff changeset
2213 }
kono
parents:
diff changeset
2214
kono
parents:
diff changeset
2215 return "";
kono
parents:
diff changeset
2216 }
kono
parents:
diff changeset
2217
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2218 /* Implement PUSH_ROUNDING. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2219
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2220 poly_int64
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2221 cr16_push_rounding (poly_int64 bytes)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2222 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2223 return (bytes + 1) & ~1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2224 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2225
111
kono
parents:
diff changeset
2226 /* Initialize 'targetm' variable which contains pointers to functions
kono
parents:
diff changeset
2227 and data relating to the target machine. */
kono
parents:
diff changeset
2228
kono
parents:
diff changeset
2229 struct gcc_target targetm = TARGET_INITIALIZER;