]>
Commit | Line | Data |
---|---|---|
ba8ab355 | 1 | /* Subroutines used for code generation on intel 80960. |
3d2cfac6 | 2 | Copyright (C) 1992, 1995, 1996, 1997, 1998, 1999, 2000 |
c2749e2d | 3 | Free Software Foundation, Inc. |
ba8ab355 JW |
4 | Contributed by Steven McGeady, Intel Corp. |
5 | Additional Work by Glenn Colon-Bonet, Jonathan Shapiro, Andy Wilson | |
6 | Converted to GCC 2.0 by Jim Wilson and Michael Tiemann, Cygnus Support. | |
7 | ||
8 | This file is part of GNU CC. | |
9 | ||
10 | GNU CC is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2, or (at your option) | |
13 | any later version. | |
14 | ||
15 | GNU CC is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with GNU CC; see the file COPYING. If not, write to | |
5b1a918b RK |
22 | the Free Software Foundation, 59 Temple Place - Suite 330, |
23 | Boston, MA 02111-1307, USA. */ | |
ba8ab355 | 24 | |
ba8ab355 | 25 | #include "config.h" |
c5c76735 | 26 | #include "system.h" |
3d2cfac6 | 27 | #include <math.h> |
ba8ab355 JW |
28 | #include "rtl.h" |
29 | #include "regs.h" | |
30 | #include "hard-reg-set.h" | |
31 | #include "real.h" | |
32 | #include "insn-config.h" | |
33 | #include "conditions.h" | |
34 | #include "insn-flags.h" | |
35 | #include "output.h" | |
36 | #include "insn-attr.h" | |
37 | #include "flags.h" | |
38 | #include "tree.h" | |
39 | #include "insn-codes.h" | |
ba8ab355 | 40 | #include "expr.h" |
5bcff23f | 41 | #include "except.h" |
ba8ab355 JW |
42 | #include "function.h" |
43 | #include "recog.h" | |
a157febd | 44 | #include "toplev.h" |
8b97c5f8 ZW |
45 | #include "cpplib.h" |
46 | #include "c-pragma.h" | |
47 | #include "c-lex.h" | |
3d2cfac6 | 48 | #include "tm_p.h" |
ba8ab355 JW |
49 | |
50 | /* Save the operands last given to a compare for use when we | |
51 | generate a scc or bcc insn. */ | |
52 | ||
53 | rtx i960_compare_op0, i960_compare_op1; | |
54 | ||
55 | /* Used to implement #pragma align/noalign. Initialized by OVERRIDE_OPTIONS | |
56 | macro in i960.h. */ | |
57 | ||
58 | static int i960_maxbitalignment; | |
59 | static int i960_last_maxbitalignment; | |
60 | ||
61 | /* Used to implement switching between MEM and ALU insn types, for better | |
62 | C series performance. */ | |
63 | ||
64 | enum insn_types i960_last_insn_type; | |
65 | ||
ba8ab355 JW |
66 | /* The leaf-procedure return register. Set only if this is a leaf routine. */ |
67 | ||
68 | static int i960_leaf_ret_reg; | |
69 | ||
70 | /* True if replacing tail calls with jumps is OK. */ | |
71 | ||
72 | static int tail_call_ok; | |
73 | ||
74 | /* A string containing a list of insns to emit in the epilogue so as to | |
75 | restore all registers saved by the prologue. Created by the prologue | |
76 | code as it saves registers away. */ | |
77 | ||
78 | char epilogue_string[1000]; | |
79 | ||
80 | /* A unique number (per function) for return labels. */ | |
81 | ||
82 | static int ret_label = 0; | |
83 | ||
c25d3f20 JW |
84 | /* This is true if FNDECL is either a varargs or a stdarg function. |
85 | This is used to help identify functions that use an argument block. */ | |
86 | ||
87 | #define VARARGS_STDARG_FUNCTION(FNDECL) \ | |
88 | ((TYPE_ARG_TYPES (TREE_TYPE (FNDECL)) != 0 \ | |
89 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (FNDECL)))) != void_type_node)) \ | |
90 | || current_function_varargs) | |
91 | ||
ba8ab355 JW |
92 | /* Handle pragmas for compatibility with Intel's compilers. */ |
93 | ||
8b97c5f8 ZW |
94 | /* NOTE: ic960 R3.0 pragma align definition: |
95 | ||
96 | #pragma align [(size)] | (identifier=size[,...]) | |
97 | #pragma noalign [(identifier)[,...]] | |
98 | ||
99 | (all parens are optional) | |
100 | ||
101 | - size is [1,2,4,8,16] | |
102 | - noalign means size==1 | |
103 | - applies only to component elements of a struct (and union?) | |
104 | - identifier applies to structure tag (only) | |
105 | - missing identifier means next struct | |
106 | ||
107 | - alignment rules for bitfields need more investigation. | |
108 | ||
109 | This implementation only handles the case of no identifiers. */ | |
110 | ||
111 | void | |
112 | i960_pr_align (pfile) | |
113 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
114 | { | |
115 | tree number; | |
116 | enum cpp_ttype type; | |
117 | int align; | |
118 | ||
119 | type = c_lex (&number); | |
120 | if (type == CPP_OPEN_PAREN) | |
121 | type = c_lex (&number); | |
122 | if (type == CPP_NAME) | |
123 | { | |
124 | warning ("sorry, not implemented: #pragma align NAME=SIZE"); | |
125 | return; | |
126 | } | |
127 | if (type != CPP_NUMBER) | |
128 | { | |
129 | warning ("malformed #pragma align - ignored"); | |
130 | return; | |
131 | } | |
132 | ||
133 | align = TREE_INT_CST_LOW (number); | |
134 | switch (align) | |
135 | { | |
136 | case 0: | |
137 | /* Return to last alignment. */ | |
138 | align = i960_last_maxbitalignment / 8; | |
139 | /* Fall through. */ | |
140 | case 16: | |
141 | case 8: | |
142 | case 4: | |
143 | case 2: | |
144 | case 1: | |
145 | i960_last_maxbitalignment = i960_maxbitalignment; | |
146 | i960_maxbitalignment = align * 8; | |
147 | break; | |
148 | ||
149 | default: | |
150 | /* Silently ignore bad values. */ | |
151 | break; | |
152 | } | |
153 | } | |
154 | ||
155 | void | |
156 | i960_pr_noalign (pfile) | |
157 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
158 | { | |
159 | enum cpp_ttype type; | |
160 | tree number; | |
161 | ||
162 | type = c_lex (&number); | |
163 | if (type == CPP_OPEN_PAREN) | |
164 | type = c_lex (&number); | |
165 | if (type == CPP_NAME) | |
166 | { | |
167 | warning ("sorry, not implemented: #pragma noalign NAME"); | |
168 | return; | |
169 | } | |
170 | ||
171 | i960_last_maxbitalignment = i960_maxbitalignment; | |
172 | i960_maxbitalignment = 8; | |
173 | } | |
ba8ab355 | 174 | |
05a81fe5 | 175 | int |
67988bd2 | 176 | process_pragma (p_getc, p_ungetc, pname) |
3d2cfac6 KG |
177 | int (* p_getc) PARAMS ((void)); |
178 | void (* p_ungetc) PARAMS ((int)); | |
179 | const char *pname; | |
ba8ab355 | 180 | { |
119d0c36 | 181 | register int c; |
67988bd2 NC |
182 | char buf[20]; |
183 | char *s = buf; | |
184 | int align; | |
ba8ab355 | 185 | |
67988bd2 NC |
186 | /* Should be pragma 'far' or equivalent for callx/balx here. */ |
187 | if (strcmp (pname, "align") != 0) | |
119d0c36 | 188 | return 0; |
67988bd2 NC |
189 | |
190 | do | |
191 | { | |
192 | c = p_getc (); | |
193 | } | |
194 | while (c == ' ' || c == '\t'); | |
ba8ab355 | 195 | |
67988bd2 NC |
196 | if (c == '(') |
197 | c = p_getc (); | |
198 | ||
199 | while (c >= '0' && c <= '9') | |
c9040e2c | 200 | { |
67988bd2 NC |
201 | if (s < buf + sizeof buf - 1) |
202 | *s++ = c; | |
203 | c = p_getc (); | |
c9040e2c | 204 | } |
67988bd2 NC |
205 | |
206 | *s = '\0'; | |
ba8ab355 | 207 | |
67988bd2 NC |
208 | /* We had to read a non-numerical character to get out of the |
209 | while loop---often a newline. So, we have to put it back to | |
210 | make sure we continue to parse everything properly. */ | |
211 | ||
212 | p_ungetc (c); | |
213 | ||
214 | align = atoi (buf); | |
c9040e2c | 215 | |
67988bd2 | 216 | |
67988bd2 NC |
217 | |
218 | return 1; | |
ba8ab355 | 219 | } |
ba8ab355 JW |
220 | |
221 | /* Initialize variables before compiling any files. */ | |
222 | ||
223 | void | |
224 | i960_initialize () | |
225 | { | |
226 | if (TARGET_IC_COMPAT2_0) | |
227 | { | |
228 | i960_maxbitalignment = 8; | |
229 | i960_last_maxbitalignment = 128; | |
230 | } | |
231 | else | |
232 | { | |
233 | i960_maxbitalignment = 128; | |
234 | i960_last_maxbitalignment = 8; | |
235 | } | |
236 | } | |
237 | \f | |
238 | /* Return true if OP can be used as the source of an fp move insn. */ | |
239 | ||
240 | int | |
241 | fpmove_src_operand (op, mode) | |
242 | rtx op; | |
243 | enum machine_mode mode; | |
244 | { | |
245 | return (GET_CODE (op) == CONST_DOUBLE || general_operand (op, mode)); | |
246 | } | |
247 | ||
248 | #if 0 | |
249 | /* Return true if OP is a register or zero. */ | |
250 | ||
251 | int | |
252 | reg_or_zero_operand (op, mode) | |
253 | rtx op; | |
254 | enum machine_mode mode; | |
255 | { | |
256 | return register_operand (op, mode) || op == const0_rtx; | |
257 | } | |
258 | #endif | |
259 | ||
260 | /* Return truth value of whether OP can be used as an operands in a three | |
261 | address arithmetic insn (such as add %o1,7,%l2) of mode MODE. */ | |
262 | ||
263 | int | |
264 | arith_operand (op, mode) | |
265 | rtx op; | |
266 | enum machine_mode mode; | |
267 | { | |
268 | return (register_operand (op, mode) || literal (op, mode)); | |
269 | } | |
270 | ||
f20200f4 TG |
271 | /* Return truth value of whether OP can be used as an operands in a three |
272 | address logic insn, possibly complementing OP, of mode MODE. */ | |
273 | ||
274 | int | |
275 | logic_operand (op, mode) | |
276 | rtx op; | |
277 | enum machine_mode mode; | |
278 | { | |
279 | return (register_operand (op, mode) | |
280 | || (GET_CODE (op) == CONST_INT | |
281 | && INTVAL(op) >= -32 && INTVAL(op) < 32)); | |
282 | } | |
283 | ||
ba8ab355 JW |
284 | /* Return true if OP is a register or a valid floating point literal. */ |
285 | ||
286 | int | |
287 | fp_arith_operand (op, mode) | |
288 | rtx op; | |
289 | enum machine_mode mode; | |
290 | { | |
291 | return (register_operand (op, mode) || fp_literal (op, mode)); | |
292 | } | |
293 | ||
294 | /* Return true is OP is a register or a valid signed integer literal. */ | |
295 | ||
296 | int | |
297 | signed_arith_operand (op, mode) | |
298 | rtx op; | |
299 | enum machine_mode mode; | |
300 | { | |
301 | return (register_operand (op, mode) || signed_literal (op, mode)); | |
302 | } | |
303 | ||
304 | /* Return truth value of whether OP is a integer which fits the | |
305 | range constraining immediate operands in three-address insns. */ | |
306 | ||
307 | int | |
308 | literal (op, mode) | |
309 | rtx op; | |
3d2cfac6 | 310 | enum machine_mode mode ATTRIBUTE_UNUSED; |
ba8ab355 JW |
311 | { |
312 | return ((GET_CODE (op) == CONST_INT) && INTVAL(op) >= 0 && INTVAL(op) < 32); | |
313 | } | |
314 | ||
315 | /* Return true if OP is a float constant of 1. */ | |
316 | ||
317 | int | |
318 | fp_literal_one (op, mode) | |
319 | rtx op; | |
320 | enum machine_mode mode; | |
321 | { | |
5cca7d17 | 322 | return (TARGET_NUMERICS && mode == GET_MODE (op) && op == CONST1_RTX (mode)); |
ba8ab355 JW |
323 | } |
324 | ||
325 | /* Return true if OP is a float constant of 0. */ | |
326 | ||
327 | int | |
328 | fp_literal_zero (op, mode) | |
329 | rtx op; | |
330 | enum machine_mode mode; | |
331 | { | |
5cca7d17 | 332 | return (TARGET_NUMERICS && mode == GET_MODE (op) && op == CONST0_RTX (mode)); |
ba8ab355 JW |
333 | } |
334 | ||
335 | /* Return true if OP is a valid floating point literal. */ | |
336 | ||
337 | int | |
338 | fp_literal(op, mode) | |
339 | rtx op; | |
340 | enum machine_mode mode; | |
341 | { | |
342 | return fp_literal_zero (op, mode) || fp_literal_one (op, mode); | |
343 | } | |
344 | ||
345 | /* Return true if OP is a valid signed immediate constant. */ | |
346 | ||
347 | int | |
348 | signed_literal(op, mode) | |
349 | rtx op; | |
3d2cfac6 | 350 | enum machine_mode mode ATTRIBUTE_UNUSED; |
ba8ab355 JW |
351 | { |
352 | return ((GET_CODE (op) == CONST_INT) && INTVAL(op) > -32 && INTVAL(op) < 32); | |
353 | } | |
354 | ||
355 | /* Return truth value of statement that OP is a symbolic memory | |
356 | operand of mode MODE. */ | |
357 | ||
358 | int | |
359 | symbolic_memory_operand (op, mode) | |
360 | rtx op; | |
3d2cfac6 | 361 | enum machine_mode mode ATTRIBUTE_UNUSED; |
ba8ab355 JW |
362 | { |
363 | if (GET_CODE (op) == SUBREG) | |
364 | op = SUBREG_REG (op); | |
365 | if (GET_CODE (op) != MEM) | |
366 | return 0; | |
367 | op = XEXP (op, 0); | |
368 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST | |
369 | || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF); | |
370 | } | |
371 | ||
372 | /* Return truth value of whether OP is EQ or NE. */ | |
373 | ||
374 | int | |
375 | eq_or_neq (op, mode) | |
376 | rtx op; | |
3d2cfac6 | 377 | enum machine_mode mode ATTRIBUTE_UNUSED; |
ba8ab355 JW |
378 | { |
379 | return (GET_CODE (op) == EQ || GET_CODE (op) == NE); | |
380 | } | |
381 | ||
382 | /* OP is an integer register or a constant. */ | |
383 | ||
384 | int | |
385 | arith32_operand (op, mode) | |
386 | rtx op; | |
387 | enum machine_mode mode; | |
388 | { | |
389 | if (register_operand (op, mode)) | |
390 | return 1; | |
391 | return (CONSTANT_P (op)); | |
392 | } | |
393 | ||
394 | /* Return true if OP is an integer constant which is a power of 2. */ | |
395 | ||
396 | int | |
397 | power2_operand (op,mode) | |
398 | rtx op; | |
3d2cfac6 | 399 | enum machine_mode mode ATTRIBUTE_UNUSED; |
ba8ab355 | 400 | { |
b47de04b | 401 | if (GET_CODE (op) != CONST_INT) |
ba8ab355 JW |
402 | return 0; |
403 | ||
404 | return exact_log2 (INTVAL (op)) >= 0; | |
405 | } | |
406 | ||
b47de04b JW |
407 | /* Return true if OP is an integer constant which is the complement of a |
408 | power of 2. */ | |
409 | ||
410 | int | |
411 | cmplpower2_operand (op, mode) | |
412 | rtx op; | |
3d2cfac6 | 413 | enum machine_mode mode ATTRIBUTE_UNUSED; |
b47de04b JW |
414 | { |
415 | if (GET_CODE (op) != CONST_INT) | |
416 | return 0; | |
417 | ||
418 | return exact_log2 (~ INTVAL (op)) >= 0; | |
419 | } | |
420 | ||
ba8ab355 JW |
421 | /* If VAL has only one bit set, return the index of that bit. Otherwise |
422 | return -1. */ | |
423 | ||
424 | int | |
425 | bitpos (val) | |
426 | unsigned int val; | |
427 | { | |
428 | register int i; | |
429 | ||
430 | for (i = 0; val != 0; i++, val >>= 1) | |
431 | { | |
432 | if (val & 1) | |
433 | { | |
434 | if (val != 1) | |
435 | return -1; | |
436 | return i; | |
437 | } | |
438 | } | |
439 | return -1; | |
440 | } | |
441 | ||
442 | /* Return non-zero if OP is a mask, i.e. all one bits are consecutive. | |
443 | The return value indicates how many consecutive non-zero bits exist | |
444 | if this is a mask. This is the same as the next function, except that | |
445 | it does not indicate what the start and stop bit positions are. */ | |
446 | ||
447 | int | |
448 | is_mask (val) | |
449 | unsigned int val; | |
450 | { | |
451 | register int start, end, i; | |
452 | ||
453 | start = -1; | |
454 | for (i = 0; val != 0; val >>= 1, i++) | |
455 | { | |
456 | if (val & 1) | |
457 | { | |
458 | if (start < 0) | |
459 | start = i; | |
460 | ||
461 | end = i; | |
462 | continue; | |
463 | } | |
464 | /* Still looking for the first bit. */ | |
465 | if (start < 0) | |
466 | continue; | |
467 | ||
468 | /* We've seen the start of a bit sequence, and now a zero. There | |
469 | must be more one bits, otherwise we would have exited the loop. | |
470 | Therefore, it is not a mask. */ | |
471 | if (val) | |
472 | return 0; | |
473 | } | |
474 | ||
475 | /* The bit string has ones from START to END bit positions only. */ | |
476 | return end - start + 1; | |
477 | } | |
478 | ||
479 | /* If VAL is a mask, then return nonzero, with S set to the starting bit | |
480 | position and E set to the ending bit position of the mask. The return | |
481 | value indicates how many consecutive bits exist in the mask. This is | |
482 | the same as the previous function, except that it also indicates the | |
483 | start and end bit positions of the mask. */ | |
484 | ||
485 | int | |
486 | bitstr (val, s, e) | |
487 | unsigned int val; | |
488 | int *s, *e; | |
489 | { | |
490 | register int start, end, i; | |
491 | ||
492 | start = -1; | |
493 | end = -1; | |
494 | for (i = 0; val != 0; val >>= 1, i++) | |
495 | { | |
496 | if (val & 1) | |
497 | { | |
498 | if (start < 0) | |
499 | start = i; | |
500 | ||
501 | end = i; | |
502 | continue; | |
503 | } | |
504 | ||
505 | /* Still looking for the first bit. */ | |
506 | if (start < 0) | |
507 | continue; | |
508 | ||
509 | /* We've seen the start of a bit sequence, and now a zero. There | |
510 | must be more one bits, otherwise we would have exited the loop. | |
511 | Therefor, it is not a mask. */ | |
512 | if (val) | |
513 | { | |
514 | start = -1; | |
515 | end = -1; | |
516 | break; | |
517 | } | |
518 | } | |
519 | ||
520 | /* The bit string has ones from START to END bit positions only. */ | |
521 | *s = start; | |
522 | *e = end; | |
523 | return ((start < 0) ? 0 : end - start + 1); | |
524 | } | |
525 | \f | |
526 | /* Return the machine mode to use for a comparison. */ | |
527 | ||
528 | enum machine_mode | |
529 | select_cc_mode (op, x) | |
530 | RTX_CODE op; | |
3d2cfac6 | 531 | rtx x ATTRIBUTE_UNUSED; |
ba8ab355 JW |
532 | { |
533 | if (op == GTU || op == LTU || op == GEU || op == LEU) | |
534 | return CC_UNSmode; | |
535 | return CCmode; | |
536 | } | |
537 | ||
538 | /* X and Y are two things to compare using CODE. Emit the compare insn and | |
539 | return the rtx for register 36 in the proper mode. */ | |
540 | ||
541 | rtx | |
542 | gen_compare_reg (code, x, y) | |
543 | enum rtx_code code; | |
544 | rtx x, y; | |
545 | { | |
546 | rtx cc_reg; | |
679655e6 | 547 | enum machine_mode ccmode = SELECT_CC_MODE (code, x, y); |
ba8ab355 JW |
548 | enum machine_mode mode |
549 | = GET_MODE (x) == VOIDmode ? GET_MODE (y) : GET_MODE (x); | |
550 | ||
551 | if (mode == SImode) | |
552 | { | |
553 | if (! arith_operand (x, mode)) | |
554 | x = force_reg (SImode, x); | |
555 | if (! arith_operand (y, mode)) | |
556 | y = force_reg (SImode, y); | |
557 | } | |
558 | ||
c5c76735 JL |
559 | cc_reg = gen_rtx_REG (ccmode, 36); |
560 | emit_insn (gen_rtx_SET (VOIDmode, cc_reg, | |
561 | gen_rtx_COMPARE (ccmode, x, y))); | |
ba8ab355 JW |
562 | |
563 | return cc_reg; | |
564 | } | |
565 | ||
566 | /* For the i960, REG is cost 1, REG+immed CONST is cost 2, REG+REG is cost 2, | |
567 | REG+nonimmed CONST is cost 4. REG+SYMBOL_REF, SYMBOL_REF, and similar | |
568 | are 4. Indexed addresses are cost 6. */ | |
569 | ||
570 | /* ??? Try using just RTX_COST, i.e. not defining ADDRESS_COST. */ | |
571 | ||
572 | int | |
573 | i960_address_cost (x) | |
574 | rtx x; | |
575 | { | |
576 | #if 0 | |
577 | /* Handled before calling here. */ | |
578 | if (GET_CODE (x) == REG) | |
579 | return 1; | |
580 | #endif | |
3410b2f3 AM |
581 | /* This is a MEMA operand -- it's free. */ |
582 | if (GET_CODE (x) == CONST_INT | |
583 | && INTVAL (x) >= 0 | |
584 | && INTVAL (x) < 4096) | |
585 | return 0; | |
586 | ||
ba8ab355 JW |
587 | if (GET_CODE (x) == PLUS) |
588 | { | |
589 | rtx base = XEXP (x, 0); | |
590 | rtx offset = XEXP (x, 1); | |
591 | ||
592 | if (GET_CODE (base) == SUBREG) | |
593 | base = SUBREG_REG (base); | |
594 | if (GET_CODE (offset) == SUBREG) | |
595 | offset = SUBREG_REG (offset); | |
596 | ||
597 | if (GET_CODE (base) == REG) | |
598 | { | |
599 | if (GET_CODE (offset) == REG) | |
600 | return 2; | |
601 | if (GET_CODE (offset) == CONST_INT) | |
602 | { | |
603 | if ((unsigned)INTVAL (offset) < 2047) | |
604 | return 2; | |
605 | return 4; | |
606 | } | |
607 | if (CONSTANT_P (offset)) | |
608 | return 4; | |
609 | } | |
610 | if (GET_CODE (base) == PLUS || GET_CODE (base) == MULT) | |
611 | return 6; | |
612 | ||
c0954bcd JW |
613 | /* This is an invalid address. The return value doesn't matter, but |
614 | for convenience we make this more expensive than anything else. */ | |
615 | return 12; | |
ba8ab355 JW |
616 | } |
617 | if (GET_CODE (x) == MULT) | |
618 | return 6; | |
619 | ||
620 | /* Symbol_refs and other unrecognized addresses are cost 4. */ | |
621 | return 4; | |
622 | } | |
623 | \f | |
624 | /* Emit insns to move operands[1] into operands[0]. | |
625 | ||
626 | Return 1 if we have written out everything that needs to be done to | |
627 | do the move. Otherwise, return 0 and the caller will emit the move | |
e4d26fc7 | 628 | normally. */ |
ba8ab355 JW |
629 | |
630 | int | |
631 | emit_move_sequence (operands, mode) | |
632 | rtx *operands; | |
633 | enum machine_mode mode; | |
634 | { | |
ba8ab355 | 635 | /* We can only store registers to memory. */ |
e4d26fc7 VM |
636 | |
637 | if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) != REG | |
638 | && (operands[1] != const0_rtx || current_function_args_size | |
639 | || current_function_varargs || current_function_stdarg | |
640 | || rtx_equal_function_value_matters)) | |
641 | /* Here we use the same test as movsi+1 pattern -- see i960.md. */ | |
3a89bbcb RK |
642 | operands[1] = force_reg (mode, operands[1]); |
643 | ||
644 | /* Storing multi-word values in unaligned hard registers to memory may | |
645 | require a scratch since we have to store them a register at a time and | |
646 | adding 4 to the memory address may not yield a valid insn. */ | |
647 | /* ??? We don't always need the scratch, but that would complicate things. | |
648 | Maybe later. */ | |
e5e809f4 JL |
649 | /* ??? We must also handle stores to pseudos here, because the pseudo may be |
650 | replaced with a MEM later. This would be cleaner if we didn't have | |
651 | a separate pattern for unaligned DImode/TImode stores. */ | |
3a89bbcb | 652 | if (GET_MODE_SIZE (mode) > UNITS_PER_WORD |
e5e809f4 JL |
653 | && (GET_CODE (operands[0]) == MEM |
654 | || (GET_CODE (operands[0]) == REG | |
655 | && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER)) | |
3a89bbcb RK |
656 | && GET_CODE (operands[1]) == REG |
657 | && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER | |
658 | && ! HARD_REGNO_MODE_OK (REGNO (operands[1]), mode)) | |
659 | { | |
c5c76735 JL |
660 | emit_insn (gen_rtx_PARALLEL |
661 | (VOIDmode, | |
662 | gen_rtvec (2, | |
663 | gen_rtx_SET (VOIDmode, operands[0], operands[1]), | |
664 | gen_rtx_CLOBBER (VOIDmode, | |
665 | gen_rtx_SCRATCH (Pmode))))); | |
3a89bbcb RK |
666 | return 1; |
667 | } | |
ba8ab355 JW |
668 | |
669 | return 0; | |
670 | } | |
3a89bbcb RK |
671 | |
672 | /* Output assembler to move a double word value. */ | |
673 | ||
3d2cfac6 | 674 | const char * |
3a89bbcb RK |
675 | i960_output_move_double (dst, src) |
676 | rtx dst, src; | |
677 | { | |
678 | rtx operands[5]; | |
679 | ||
680 | if (GET_CODE (dst) == REG | |
681 | && GET_CODE (src) == REG) | |
682 | { | |
683 | if ((REGNO (src) & 1) | |
684 | || (REGNO (dst) & 1)) | |
685 | { | |
686 | /* We normally copy the low-numbered register first. However, if | |
687 | the second source register is the same as the first destination | |
688 | register, we must copy in the opposite order. */ | |
689 | if (REGNO (src) + 1 == REGNO (dst)) | |
690 | return "mov %D1,%D0\n\tmov %1,%0"; | |
691 | else | |
692 | return "mov %1,%0\n\tmov %D1,%D0"; | |
693 | } | |
694 | else | |
695 | return "movl %1,%0"; | |
696 | } | |
697 | else if (GET_CODE (dst) == REG | |
698 | && GET_CODE (src) == CONST_INT | |
699 | && CONST_OK_FOR_LETTER_P (INTVAL (src), 'I')) | |
700 | { | |
701 | if (REGNO (dst) & 1) | |
702 | return "mov %1,%0\n\tmov 0,%D0"; | |
703 | else | |
704 | return "movl %1,%0"; | |
705 | } | |
706 | else if (GET_CODE (dst) == REG | |
707 | && GET_CODE (src) == MEM) | |
708 | { | |
709 | if (REGNO (dst) & 1) | |
710 | { | |
711 | /* One can optimize a few cases here, but you have to be | |
712 | careful of clobbering registers used in the address and | |
713 | edge conditions. */ | |
714 | operands[0] = dst; | |
715 | operands[1] = src; | |
c5c76735 JL |
716 | operands[2] = gen_rtx_REG (Pmode, REGNO (dst) + 1); |
717 | operands[3] = gen_rtx_MEM (word_mode, operands[2]); | |
3a89bbcb RK |
718 | operands[4] = adj_offsettable_operand (operands[3], UNITS_PER_WORD); |
719 | output_asm_insn ("lda %1,%2\n\tld %3,%0\n\tld %4,%D0", operands); | |
720 | return ""; | |
721 | } | |
722 | else | |
723 | return "ldl %1,%0"; | |
724 | } | |
725 | else if (GET_CODE (dst) == MEM | |
726 | && GET_CODE (src) == REG) | |
727 | { | |
728 | if (REGNO (src) & 1) | |
729 | { | |
e4d26fc7 VM |
730 | operands[0] = dst; |
731 | operands[1] = adj_offsettable_operand (dst, UNITS_PER_WORD); | |
732 | if (! memory_address_p (word_mode, XEXP (operands[1], 0))) | |
733 | abort (); | |
734 | operands[2] = src; | |
735 | output_asm_insn ("st %2,%0\n\tst %D2,%1", operands); | |
736 | return ""; | |
3a89bbcb RK |
737 | } |
738 | return "stl %1,%0"; | |
739 | } | |
740 | else | |
741 | abort (); | |
742 | } | |
743 | ||
e4d26fc7 VM |
744 | /* Output assembler to move a double word zero. */ |
745 | ||
3d2cfac6 | 746 | const char * |
e4d26fc7 VM |
747 | i960_output_move_double_zero (dst) |
748 | rtx dst; | |
749 | { | |
750 | rtx operands[2]; | |
751 | ||
752 | operands[0] = dst; | |
753 | { | |
754 | operands[1] = adj_offsettable_operand (dst, 4); | |
755 | output_asm_insn ("st g14,%0\n\tst g14,%1", operands); | |
756 | } | |
757 | return ""; | |
758 | } | |
759 | ||
3a89bbcb RK |
760 | /* Output assembler to move a quad word value. */ |
761 | ||
3d2cfac6 | 762 | const char * |
3a89bbcb RK |
763 | i960_output_move_quad (dst, src) |
764 | rtx dst, src; | |
765 | { | |
766 | rtx operands[7]; | |
767 | ||
768 | if (GET_CODE (dst) == REG | |
769 | && GET_CODE (src) == REG) | |
770 | { | |
771 | if ((REGNO (src) & 3) | |
772 | || (REGNO (dst) & 3)) | |
773 | { | |
774 | /* We normally copy starting with the low numbered register. | |
775 | However, if there is an overlap such that the first dest reg | |
776 | is <= the last source reg but not < the first source reg, we | |
777 | must copy in the opposite order. */ | |
778 | if (REGNO (dst) <= REGNO (src) + 3 | |
779 | && REGNO (dst) >= REGNO (src)) | |
780 | return "mov %F1,%F0\n\tmov %E1,%E0\n\tmov %D1,%D0\n\tmov %1,%0"; | |
781 | else | |
782 | return "mov %1,%0\n\tmov %D1,%D0\n\tmov %E1,%E0\n\tmov %F1,%F0"; | |
783 | } | |
784 | else | |
785 | return "movq %1,%0"; | |
786 | } | |
787 | else if (GET_CODE (dst) == REG | |
788 | && GET_CODE (src) == CONST_INT | |
789 | && CONST_OK_FOR_LETTER_P (INTVAL (src), 'I')) | |
790 | { | |
791 | if (REGNO (dst) & 3) | |
792 | return "mov %1,%0\n\tmov 0,%D0\n\tmov 0,%E0\n\tmov 0,%F0"; | |
793 | else | |
794 | return "movq %1,%0"; | |
795 | } | |
796 | else if (GET_CODE (dst) == REG | |
797 | && GET_CODE (src) == MEM) | |
798 | { | |
799 | if (REGNO (dst) & 3) | |
800 | { | |
801 | /* One can optimize a few cases here, but you have to be | |
802 | careful of clobbering registers used in the address and | |
803 | edge conditions. */ | |
804 | operands[0] = dst; | |
805 | operands[1] = src; | |
c5c76735 JL |
806 | operands[2] = gen_rtx_REG (Pmode, REGNO (dst) + 3); |
807 | operands[3] = gen_rtx_MEM (word_mode, operands[2]); | |
3a89bbcb RK |
808 | operands[4] = adj_offsettable_operand (operands[3], UNITS_PER_WORD); |
809 | operands[5] = adj_offsettable_operand (operands[4], UNITS_PER_WORD); | |
810 | operands[6] = adj_offsettable_operand (operands[5], UNITS_PER_WORD); | |
811 | output_asm_insn ("lda %1,%2\n\tld %3,%0\n\tld %4,%D0\n\tld %5,%E0\n\tld %6,%F0", operands); | |
812 | return ""; | |
813 | } | |
814 | else | |
815 | return "ldq %1,%0"; | |
816 | } | |
817 | else if (GET_CODE (dst) == MEM | |
818 | && GET_CODE (src) == REG) | |
819 | { | |
820 | if (REGNO (src) & 3) | |
821 | { | |
e4d26fc7 VM |
822 | operands[0] = dst; |
823 | operands[1] = adj_offsettable_operand (dst, UNITS_PER_WORD); | |
824 | operands[2] = adj_offsettable_operand (dst, 2*UNITS_PER_WORD); | |
825 | operands[3] = adj_offsettable_operand (dst, 3*UNITS_PER_WORD); | |
826 | if (! memory_address_p (word_mode, XEXP (operands[3], 0))) | |
827 | abort (); | |
828 | operands[4] = src; | |
829 | output_asm_insn ("st %4,%0\n\tst %D4,%1\n\tst %E4,%2\n\tst %F4,%3", operands); | |
830 | return ""; | |
3a89bbcb RK |
831 | } |
832 | return "stq %1,%0"; | |
833 | } | |
834 | else | |
835 | abort (); | |
836 | } | |
e4d26fc7 VM |
837 | |
838 | /* Output assembler to move a quad word zero. */ | |
839 | ||
3d2cfac6 | 840 | const char * |
e4d26fc7 VM |
841 | i960_output_move_quad_zero (dst) |
842 | rtx dst; | |
843 | { | |
844 | rtx operands[4]; | |
845 | ||
846 | operands[0] = dst; | |
847 | { | |
848 | operands[1] = adj_offsettable_operand (dst, 4); | |
849 | operands[2] = adj_offsettable_operand (dst, 8); | |
850 | operands[3] = adj_offsettable_operand (dst, 12); | |
851 | output_asm_insn ("st g14,%0\n\tst g14,%1\n\tst g14,%2\n\tst g14,%3", operands); | |
852 | } | |
853 | return ""; | |
854 | } | |
855 | ||
ba8ab355 | 856 | \f |
37aba850 TG |
857 | /* Emit insns to load a constant to non-floating point registers. |
858 | Uses several strategies to try to use as few insns as possible. */ | |
ba8ab355 | 859 | |
3d2cfac6 | 860 | const char * |
ba8ab355 JW |
861 | i960_output_ldconst (dst, src) |
862 | register rtx dst, src; | |
863 | { | |
864 | register int rsrc1; | |
865 | register unsigned rsrc2; | |
866 | enum machine_mode mode = GET_MODE (dst); | |
867 | rtx operands[4]; | |
ba8ab355 JW |
868 | |
869 | operands[0] = operands[2] = dst; | |
870 | operands[1] = operands[3] = src; | |
871 | ||
872 | /* Anything that isn't a compile time constant, such as a SYMBOL_REF, | |
873 | must be a ldconst insn. */ | |
874 | ||
875 | if (GET_CODE (src) != CONST_INT && GET_CODE (src) != CONST_DOUBLE) | |
876 | { | |
877 | output_asm_insn ("ldconst %1,%0", operands); | |
878 | return ""; | |
879 | } | |
37aba850 TG |
880 | else if (mode == XFmode) |
881 | { | |
882 | REAL_VALUE_TYPE d; | |
883 | long value_long[3]; | |
884 | int i; | |
885 | ||
886 | if (fp_literal_zero (src, XFmode)) | |
887 | return "movt 0,%0"; | |
888 | ||
889 | REAL_VALUE_FROM_CONST_DOUBLE (d, src); | |
890 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, value_long); | |
891 | ||
892 | output_asm_insn ("# ldconst %1,%0",operands); | |
893 | ||
894 | for (i = 0; i < 3; i++) | |
895 | { | |
c5c76735 | 896 | operands[0] = gen_rtx_REG (SImode, REGNO (dst) + i); |
37aba850 TG |
897 | operands[1] = GEN_INT (value_long[i]); |
898 | output_asm_insn (i960_output_ldconst (operands[0], operands[1]), | |
899 | operands); | |
900 | } | |
901 | ||
902 | return ""; | |
903 | } | |
ba8ab355 JW |
904 | else if (mode == DFmode) |
905 | { | |
906 | rtx first, second; | |
907 | ||
5cca7d17 JW |
908 | if (fp_literal_zero (src, DFmode)) |
909 | return "movl 0,%0"; | |
ba8ab355 | 910 | |
ba8ab355 JW |
911 | split_double (src, &first, &second); |
912 | ||
913 | output_asm_insn ("# ldconst %1,%0",operands); | |
914 | ||
c5c76735 | 915 | operands[0] = gen_rtx_REG (SImode, REGNO (dst)); |
ba8ab355 JW |
916 | operands[1] = first; |
917 | output_asm_insn (i960_output_ldconst (operands[0], operands[1]), | |
918 | operands); | |
c5c76735 | 919 | operands[0] = gen_rtx_REG (SImode, REGNO (dst) + 1); |
ba8ab355 JW |
920 | operands[1] = second; |
921 | output_asm_insn (i960_output_ldconst (operands[0], operands[1]), | |
922 | operands); | |
923 | return ""; | |
ba8ab355 | 924 | } |
37aba850 TG |
925 | else if (mode == SFmode) |
926 | { | |
927 | REAL_VALUE_TYPE d; | |
928 | long value; | |
929 | ||
930 | REAL_VALUE_FROM_CONST_DOUBLE (d, src); | |
931 | REAL_VALUE_TO_TARGET_SINGLE (d, value); | |
932 | ||
933 | output_asm_insn ("# ldconst %1,%0",operands); | |
c5c76735 | 934 | operands[0] = gen_rtx_REG (SImode, REGNO (dst)); |
3a598fbe | 935 | operands[1] = GEN_INT (value); |
37aba850 TG |
936 | output_asm_insn (i960_output_ldconst (operands[0], operands[1]), |
937 | operands); | |
938 | return ""; | |
939 | } | |
ba8ab355 JW |
940 | else if (mode == TImode) |
941 | { | |
942 | /* ??? This is currently not handled at all. */ | |
943 | abort (); | |
944 | ||
945 | /* Note: lowest order word goes in lowest numbered reg. */ | |
946 | rsrc1 = INTVAL (src); | |
947 | if (rsrc1 >= 0 && rsrc1 < 32) | |
948 | return "movq %1,%0"; | |
949 | else | |
950 | output_asm_insn ("movq\t0,%0\t# ldconstq %1,%0",operands); | |
951 | /* Go pick up the low-order word. */ | |
952 | } | |
953 | else if (mode == DImode) | |
954 | { | |
518dd866 | 955 | rtx upperhalf, lowerhalf, xoperands[2]; |
ba8ab355 | 956 | |
ca01dc12 TG |
957 | if (GET_CODE (src) == CONST_DOUBLE || GET_CODE (src) == CONST_INT) |
958 | split_double (src, &lowerhalf, &upperhalf); | |
959 | ||
ba8ab355 JW |
960 | else |
961 | abort (); | |
962 | ||
963 | /* Note: lowest order word goes in lowest numbered reg. */ | |
964 | /* Numbers from 0 to 31 can be handled with a single insn. */ | |
965 | rsrc1 = INTVAL (lowerhalf); | |
966 | if (upperhalf == const0_rtx && rsrc1 >= 0 && rsrc1 < 32) | |
967 | return "movl %1,%0"; | |
968 | ||
969 | /* Output the upper half with a recursive call. */ | |
c5c76735 | 970 | xoperands[0] = gen_rtx_REG (SImode, REGNO (dst) + 1); |
518dd866 JW |
971 | xoperands[1] = upperhalf; |
972 | output_asm_insn (i960_output_ldconst (xoperands[0], xoperands[1]), | |
973 | xoperands); | |
ba8ab355 JW |
974 | /* The lower word is emitted as normally. */ |
975 | } | |
ba8ab355 JW |
976 | else |
977 | { | |
978 | rsrc1 = INTVAL (src); | |
979 | if (mode == QImode) | |
980 | { | |
981 | if (rsrc1 > 0xff) | |
982 | rsrc1 &= 0xff; | |
983 | } | |
984 | else if (mode == HImode) | |
985 | { | |
986 | if (rsrc1 > 0xffff) | |
987 | rsrc1 &= 0xffff; | |
988 | } | |
989 | } | |
990 | ||
991 | if (rsrc1 >= 0) | |
992 | { | |
993 | /* ldconst 0..31,X -> mov 0..31,X */ | |
994 | if (rsrc1 < 32) | |
995 | { | |
996 | if (i960_last_insn_type == I_TYPE_REG && TARGET_C_SERIES) | |
997 | return "lda %1,%0"; | |
998 | return "mov %1,%0"; | |
999 | } | |
1000 | ||
1001 | /* ldconst 32..63,X -> add 31,nn,X */ | |
1002 | if (rsrc1 < 63) | |
1003 | { | |
1004 | if (i960_last_insn_type == I_TYPE_REG && TARGET_C_SERIES) | |
1005 | return "lda %1,%0"; | |
3a598fbe | 1006 | operands[1] = GEN_INT (rsrc1 - 31); |
ba8ab355 JW |
1007 | output_asm_insn ("addo\t31,%1,%0\t# ldconst %3,%0", operands); |
1008 | return ""; | |
1009 | } | |
1010 | } | |
1011 | else if (rsrc1 < 0) | |
1012 | { | |
1013 | /* ldconst -1..-31 -> sub 0,0..31,X */ | |
1014 | if (rsrc1 >= -31) | |
1015 | { | |
1016 | /* return 'sub -(%1),0,%0' */ | |
3a598fbe | 1017 | operands[1] = GEN_INT (- rsrc1); |
ba8ab355 JW |
1018 | output_asm_insn ("subo\t%1,0,%0\t# ldconst %3,%0", operands); |
1019 | return ""; | |
1020 | } | |
1021 | ||
1022 | /* ldconst -32 -> not 31,X */ | |
1023 | if (rsrc1 == -32) | |
1024 | { | |
3a598fbe | 1025 | operands[1] = GEN_INT (~rsrc1); |
ba8ab355 JW |
1026 | output_asm_insn ("not\t%1,%0 # ldconst %3,%0", operands); |
1027 | return ""; | |
1028 | } | |
1029 | } | |
1030 | ||
1031 | /* If const is a single bit. */ | |
1032 | if (bitpos (rsrc1) >= 0) | |
1033 | { | |
3a598fbe | 1034 | operands[1] = GEN_INT (bitpos (rsrc1)); |
ba8ab355 JW |
1035 | output_asm_insn ("setbit\t%1,0,%0\t# ldconst %3,%0", operands); |
1036 | return ""; | |
1037 | } | |
1038 | ||
1039 | /* If const is a bit string of less than 6 bits (1..31 shifted). */ | |
1040 | if (is_mask (rsrc1)) | |
1041 | { | |
1042 | int s, e; | |
1043 | ||
1044 | if (bitstr (rsrc1, &s, &e) < 6) | |
1045 | { | |
1046 | rsrc2 = ((unsigned int) rsrc1) >> s; | |
3a598fbe JL |
1047 | operands[1] = GEN_INT (rsrc2); |
1048 | operands[2] = GEN_INT (s); | |
ba8ab355 JW |
1049 | output_asm_insn ("shlo\t%2,%1,%0\t# ldconst %3,%0", operands); |
1050 | return ""; | |
1051 | } | |
1052 | } | |
1053 | ||
1054 | /* Unimplemented cases: | |
1055 | const is in range 0..31 but rotated around end of word: | |
1056 | ror 31,3,g0 -> ldconst 0xe0000003,g0 | |
1057 | ||
1058 | and any 2 instruction cases that might be worthwhile */ | |
1059 | ||
1060 | output_asm_insn ("ldconst %1,%0", operands); | |
1061 | return ""; | |
1062 | } | |
1063 | ||
1064 | /* Determine if there is an opportunity for a bypass optimization. | |
2296cba3 | 1065 | Bypass succeeds on the 960K* if the destination of the previous |
ba8ab355 JW |
1066 | instruction is the second operand of the current instruction. |
1067 | Bypass always succeeds on the C*. | |
1068 | ||
1069 | Return 1 if the pattern should interchange the operands. | |
1070 | ||
1071 | CMPBR_FLAG is true if this is for a compare-and-branch insn. | |
1072 | OP1 and OP2 are the two source operands of a 3 operand insn. */ | |
1073 | ||
1074 | int | |
1075 | i960_bypass (insn, op1, op2, cmpbr_flag) | |
1076 | register rtx insn, op1, op2; | |
1077 | int cmpbr_flag; | |
1078 | { | |
1079 | register rtx prev_insn, prev_dest; | |
1080 | ||
1081 | if (TARGET_C_SERIES) | |
1082 | return 0; | |
1083 | ||
1084 | /* Can't do this if op1 isn't a register. */ | |
1085 | if (! REG_P (op1)) | |
1086 | return 0; | |
1087 | ||
1088 | /* Can't do this for a compare-and-branch if both ops aren't regs. */ | |
1089 | if (cmpbr_flag && ! REG_P (op2)) | |
1090 | return 0; | |
1091 | ||
1092 | prev_insn = prev_real_insn (insn); | |
1093 | ||
1094 | if (prev_insn && GET_CODE (prev_insn) == INSN | |
1095 | && GET_CODE (PATTERN (prev_insn)) == SET) | |
1096 | { | |
1097 | prev_dest = SET_DEST (PATTERN (prev_insn)); | |
1098 | if ((GET_CODE (prev_dest) == REG && REGNO (prev_dest) == REGNO (op1)) | |
1099 | || (GET_CODE (prev_dest) == SUBREG | |
1100 | && GET_CODE (SUBREG_REG (prev_dest)) == REG | |
1101 | && REGNO (SUBREG_REG (prev_dest)) == REGNO (op1))) | |
1102 | return 1; | |
1103 | } | |
1104 | return 0; | |
1105 | } | |
1106 | \f | |
1107 | /* Output the code which declares the function name. This also handles | |
1108 | leaf routines, which have special requirements, and initializes some | |
1109 | global variables. */ | |
1110 | ||
1111 | void | |
1112 | i960_function_name_declare (file, name, fndecl) | |
1113 | FILE *file; | |
3d2cfac6 | 1114 | const char *name; |
ba8ab355 JW |
1115 | tree fndecl; |
1116 | { | |
1117 | register int i, j; | |
1118 | int leaf_proc_ok; | |
1119 | rtx insn; | |
1120 | ||
1121 | /* Increment global return label. */ | |
1122 | ||
1123 | ret_label++; | |
1124 | ||
1125 | /* Compute whether tail calls and leaf routine optimizations can be performed | |
1126 | for this function. */ | |
1127 | ||
1128 | if (TARGET_TAILCALL) | |
1129 | tail_call_ok = 1; | |
1130 | else | |
1131 | tail_call_ok = 0; | |
1132 | ||
1133 | if (TARGET_LEAFPROC) | |
1134 | leaf_proc_ok = 1; | |
1135 | else | |
1136 | leaf_proc_ok = 0; | |
1137 | ||
ddd5a7c1 | 1138 | /* Even if nobody uses extra parms, can't have leafproc or tail calls if |
ba8ab355 JW |
1139 | argblock, because argblock uses g14 implicitly. */ |
1140 | ||
c25d3f20 | 1141 | if (current_function_args_size != 0 || VARARGS_STDARG_FUNCTION (fndecl)) |
ba8ab355 JW |
1142 | { |
1143 | tail_call_ok = 0; | |
1144 | leaf_proc_ok = 0; | |
1145 | } | |
1146 | ||
1147 | /* See if caller passes in an address to return value. */ | |
1148 | ||
1149 | if (aggregate_value_p (DECL_RESULT (fndecl))) | |
1150 | { | |
1151 | tail_call_ok = 0; | |
1152 | leaf_proc_ok = 0; | |
1153 | } | |
1154 | ||
1155 | /* Can not use tail calls or make this a leaf routine if there is a non | |
1156 | zero frame size. */ | |
1157 | ||
1158 | if (get_frame_size () != 0) | |
1159 | leaf_proc_ok = 0; | |
1160 | ||
1161 | /* I don't understand this condition, and do not think that it is correct. | |
1162 | Apparently this is just checking whether the frame pointer is used, and | |
1163 | we can't trust regs_ever_live[fp] since it is (almost?) always set. */ | |
1164 | ||
1165 | if (tail_call_ok) | |
1166 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
1167 | if (GET_CODE (insn) == INSN | |
1168 | && reg_mentioned_p (frame_pointer_rtx, insn)) | |
1169 | { | |
1170 | tail_call_ok = 0; | |
1171 | break; | |
1172 | } | |
1173 | ||
1174 | /* Check for CALL insns. Can not be a leaf routine if there are any. */ | |
1175 | ||
1176 | if (leaf_proc_ok) | |
1177 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
1178 | if (GET_CODE (insn) == CALL_INSN) | |
1179 | { | |
1180 | leaf_proc_ok = 0; | |
1181 | break; | |
1182 | } | |
1183 | ||
1184 | /* Can not be a leaf routine if any non-call clobbered registers are | |
1185 | used in this function. */ | |
1186 | ||
1187 | if (leaf_proc_ok) | |
1188 | for (i = 0, j = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
1189 | if (regs_ever_live[i] | |
1190 | && ((! call_used_regs[i]) || (i > 7 && i < 12))) | |
1191 | { | |
1192 | /* Global registers. */ | |
1193 | if (i < 16 && i > 7 && i != 13) | |
1194 | leaf_proc_ok = 0; | |
1195 | /* Local registers. */ | |
1196 | else if (i < 32) | |
1197 | leaf_proc_ok = 0; | |
1198 | } | |
1199 | ||
1200 | /* Now choose a leaf return register, if we can find one, and if it is | |
1201 | OK for this to be a leaf routine. */ | |
1202 | ||
1203 | i960_leaf_ret_reg = -1; | |
1204 | ||
1205 | if (optimize && leaf_proc_ok) | |
1206 | { | |
1207 | for (i960_leaf_ret_reg = -1, i = 0; i < 8; i++) | |
1208 | if (regs_ever_live[i] == 0) | |
1209 | { | |
1210 | i960_leaf_ret_reg = i; | |
1211 | regs_ever_live[i] = 1; | |
1212 | break; | |
1213 | } | |
1214 | } | |
1215 | ||
1216 | /* Do this after choosing the leaf return register, so it will be listed | |
1217 | if one was chosen. */ | |
1218 | ||
bb562bfc | 1219 | fprintf (file, "\t# Function '%s'\n", (name[0] == '*' ? &name[1] : name)); |
ba8ab355 JW |
1220 | fprintf (file, "\t# Registers used: "); |
1221 | ||
1222 | for (i = 0, j = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
1223 | { | |
1224 | if (regs_ever_live[i]) | |
1225 | { | |
1226 | fprintf (file, "%s%s ", reg_names[i], call_used_regs[i] ? "" : "*"); | |
1227 | ||
1228 | if (i > 15 && j == 0) | |
1229 | { | |
1230 | fprintf (file,"\n\t#\t\t "); | |
1231 | j++; | |
1232 | } | |
1233 | } | |
1234 | } | |
1235 | ||
1236 | fprintf (file, "\n"); | |
1237 | ||
1238 | if (i960_leaf_ret_reg >= 0) | |
1239 | { | |
1240 | /* Make it a leaf procedure. */ | |
1241 | ||
1242 | if (TREE_PUBLIC (fndecl)) | |
bb562bfc | 1243 | fprintf (file,"\t.globl\t%s.lf\n", (name[0] == '*' ? &name[1] : name)); |
ba8ab355 | 1244 | |
bb562bfc JW |
1245 | fprintf (file, "\t.leafproc\t"); |
1246 | assemble_name (file, name); | |
1247 | fprintf (file, ",%s.lf\n", (name[0] == '*' ? &name[1] : name)); | |
1248 | ASM_OUTPUT_LABEL (file, name); | |
c3c7ea1f | 1249 | fprintf (file, "\tlda Li960R%d,g14\n", ret_label); |
bb562bfc | 1250 | fprintf (file, "%s.lf:\n", (name[0] == '*' ? &name[1] : name)); |
ba8ab355 JW |
1251 | fprintf (file, "\tmov g14,g%d\n", i960_leaf_ret_reg); |
1252 | ||
1253 | if (TARGET_C_SERIES) | |
1254 | { | |
1255 | fprintf (file, "\tlda 0,g14\n"); | |
1256 | i960_last_insn_type = I_TYPE_MEM; | |
1257 | } | |
1258 | else | |
1259 | { | |
1260 | fprintf (file, "\tmov 0,g14\n"); | |
1261 | i960_last_insn_type = I_TYPE_REG; | |
1262 | } | |
1263 | } | |
1264 | else | |
1265 | { | |
1266 | ASM_OUTPUT_LABEL (file, name); | |
1267 | i960_last_insn_type = I_TYPE_CTRL; | |
1268 | } | |
1269 | } | |
1270 | \f | |
1271 | /* Compute and return the frame size. */ | |
1272 | ||
1273 | int | |
1274 | compute_frame_size (size) | |
1275 | int size; | |
1276 | { | |
1277 | int actual_fsize; | |
c25d3f20 | 1278 | int outgoing_args_size = current_function_outgoing_args_size; |
ba8ab355 JW |
1279 | |
1280 | /* The STARTING_FRAME_OFFSET is totally hidden to us as far | |
1281 | as size is concerned. */ | |
1282 | actual_fsize = (size + 15) & -16; | |
1283 | actual_fsize += (outgoing_args_size + 15) & -16; | |
1284 | ||
1285 | return actual_fsize; | |
1286 | } | |
1287 | ||
9ef06443 VM |
1288 | /* Here register group is range of registers which can be moved by |
1289 | one i960 instruction. */ | |
1290 | ||
1291 | struct reg_group | |
1292 | { | |
1293 | char start_reg; | |
1294 | char length; | |
1295 | }; | |
1296 | ||
3d2cfac6 KG |
1297 | static int i960_form_reg_groups PARAMS ((int, int, int *, int, struct reg_group *)); |
1298 | static int i960_reg_group_compare PARAMS ((const void *, const void *)); | |
1299 | static int i960_split_reg_group PARAMS ((struct reg_group *, int, int)); | |
1300 | static void i960_arg_size_and_align PARAMS ((enum machine_mode, tree, int *, int *)); | |
1301 | ||
9ef06443 VM |
1302 | /* The following functions forms the biggest as possible register |
1303 | groups with registers in STATE. REGS contain states of the | |
1304 | registers in range [start, finish_reg). The function returns the | |
1305 | number of groups formed. */ | |
1306 | static int | |
1307 | i960_form_reg_groups (start_reg, finish_reg, regs, state, reg_groups) | |
1308 | int start_reg; | |
1309 | int finish_reg; | |
1310 | int *regs; | |
1311 | int state; | |
1312 | struct reg_group *reg_groups; | |
1313 | { | |
1314 | int i; | |
1315 | int nw = 0; | |
1316 | ||
1317 | for (i = start_reg; i < finish_reg; ) | |
1318 | { | |
1319 | if (regs [i] != state) | |
1320 | { | |
1321 | i++; | |
1322 | continue; | |
1323 | } | |
1324 | else if (i % 2 != 0 || regs [i + 1] != state) | |
1325 | reg_groups [nw].length = 1; | |
1326 | else if (i % 4 != 0 || regs [i + 2] != state) | |
1327 | reg_groups [nw].length = 2; | |
1328 | else if (regs [i + 3] != state) | |
1329 | reg_groups [nw].length = 3; | |
1330 | else | |
1331 | reg_groups [nw].length = 4; | |
1332 | reg_groups [nw].start_reg = i; | |
1333 | i += reg_groups [nw].length; | |
1334 | nw++; | |
1335 | } | |
1336 | return nw; | |
1337 | } | |
1338 | ||
1339 | /* We sort register winodws in descending order by length. */ | |
1340 | static int | |
1341 | i960_reg_group_compare (group1, group2) | |
3d2cfac6 KG |
1342 | const void *group1; |
1343 | const void *group2; | |
9ef06443 | 1344 | { |
3d2cfac6 KG |
1345 | const struct reg_group *w1 = group1; |
1346 | const struct reg_group *w2 = group2; | |
9ef06443 VM |
1347 | |
1348 | if (w1->length > w2->length) | |
1349 | return -1; | |
1350 | else if (w1->length < w2->length) | |
1351 | return 1; | |
1352 | else | |
1353 | return 0; | |
1354 | } | |
1355 | ||
1356 | /* Split the first register group in REG_GROUPS on subgroups one of | |
1357 | which will contain SUBGROUP_LENGTH registers. The function | |
1358 | returns new number of winodws. */ | |
1359 | static int | |
1360 | i960_split_reg_group (reg_groups, nw, subgroup_length) | |
1361 | struct reg_group *reg_groups; | |
1362 | int nw; | |
1363 | int subgroup_length; | |
1364 | { | |
1365 | if (subgroup_length < reg_groups->length - subgroup_length) | |
1366 | /* This guarantees correct alignments of the two subgroups for | |
1367 | i960 (see spliting for the group length 2, 3, 4). More | |
1368 | generalized algorithm would require splitting the group more | |
1369 | two subgroups. */ | |
1370 | subgroup_length = reg_groups->length - subgroup_length; | |
1371 | /* More generalized algorithm would require to try merging | |
1372 | subgroups here. But in case i960 it always results in failure | |
1373 | because of register group alignment. */ | |
1374 | reg_groups[nw].length = reg_groups->length - subgroup_length; | |
1375 | reg_groups[nw].start_reg = reg_groups->start_reg + subgroup_length; | |
1376 | nw++; | |
1377 | reg_groups->length = subgroup_length; | |
1378 | qsort (reg_groups, nw, sizeof (struct reg_group), i960_reg_group_compare); | |
1379 | return nw; | |
1380 | } | |
1381 | ||
ba8ab355 JW |
1382 | /* Output code for the function prologue. */ |
1383 | ||
1384 | void | |
1385 | i960_function_prologue (file, size) | |
1386 | FILE *file; | |
1387 | unsigned int size; | |
1388 | { | |
1389 | register int i, j, nr; | |
bcf783f4 VM |
1390 | int n_saved_regs = 0; |
1391 | int n_remaining_saved_regs; | |
1392 | int lvar_size; | |
77a02b01 | 1393 | int actual_fsize, offset; |
9ef06443 VM |
1394 | int gnw, lnw; |
1395 | struct reg_group *g, *l; | |
ba8ab355 JW |
1396 | char tmpstr[1000]; |
1397 | /* -1 if reg must be saved on proc entry, 0 if available, 1 if saved | |
1398 | somewhere. */ | |
1399 | int regs[FIRST_PSEUDO_REGISTER]; | |
9ef06443 VM |
1400 | /* All global registers (which must be saved) divided by groups. */ |
1401 | struct reg_group global_reg_groups [16]; | |
1402 | /* All local registers (which are available) divided by groups. */ | |
1403 | struct reg_group local_reg_groups [16]; | |
1404 | ||
ba8ab355 JW |
1405 | |
1406 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
1407 | if (regs_ever_live[i] | |
a45f3331 JW |
1408 | && ((! call_used_regs[i]) || (i > 7 && i < 12)) |
1409 | /* No need to save the static chain pointer. */ | |
1410 | && ! (i == STATIC_CHAIN_REGNUM && current_function_needs_context)) | |
ba8ab355 JW |
1411 | { |
1412 | regs[i] = -1; | |
1413 | /* Count global registers that need saving. */ | |
1414 | if (i < 16) | |
bcf783f4 | 1415 | n_saved_regs++; |
ba8ab355 JW |
1416 | } |
1417 | else | |
1418 | regs[i] = 0; | |
1419 | ||
bcf783f4 VM |
1420 | n_remaining_saved_regs = n_saved_regs; |
1421 | ||
ba8ab355 JW |
1422 | epilogue_string[0] = '\0'; |
1423 | ||
7a24dbcf JW |
1424 | if (profile_flag || profile_block_flag) |
1425 | { | |
1426 | /* When profiling, we may use registers 20 to 27 to save arguments, so | |
1427 | they can't be used here for saving globals. J is the number of | |
1428 | argument registers the mcount call will save. */ | |
1429 | for (j = 7; j >= 0 && ! regs_ever_live[j]; j--) | |
1430 | ; | |
1431 | ||
1432 | for (i = 20; i <= j + 20; i++) | |
1433 | regs[i] = -1; | |
1434 | } | |
1435 | ||
9ef06443 VM |
1436 | gnw = i960_form_reg_groups (0, 16, regs, -1, global_reg_groups); |
1437 | lnw = i960_form_reg_groups (19, 32, regs, 0, local_reg_groups); | |
1438 | qsort (global_reg_groups, gnw, sizeof (struct reg_group), | |
1439 | i960_reg_group_compare); | |
1440 | qsort (local_reg_groups, lnw, sizeof (struct reg_group), | |
1441 | i960_reg_group_compare); | |
1442 | for (g = global_reg_groups, l = local_reg_groups; lnw != 0 && gnw != 0;) | |
ba8ab355 | 1443 | { |
9ef06443 | 1444 | if (g->length == l->length) |
ba8ab355 | 1445 | { |
ba8ab355 | 1446 | fprintf (file, "\tmov%s %s,%s\n", |
9ef06443 VM |
1447 | ((g->length == 4) ? "q" : |
1448 | (g->length == 3) ? "t" : | |
1449 | (g->length == 2) ? "l" : ""), | |
3d2cfac6 KG |
1450 | reg_names[(unsigned char) g->start_reg], |
1451 | reg_names[(unsigned char) l->start_reg]); | |
ba8ab355 | 1452 | sprintf (tmpstr, "\tmov%s %s,%s\n", |
9ef06443 VM |
1453 | ((g->length == 4) ? "q" : |
1454 | (g->length == 3) ? "t" : | |
1455 | (g->length == 2) ? "l" : ""), | |
3d2cfac6 KG |
1456 | reg_names[(unsigned char) l->start_reg], |
1457 | reg_names[(unsigned char) g->start_reg]); | |
ba8ab355 | 1458 | strcat (epilogue_string, tmpstr); |
bcf783f4 | 1459 | n_remaining_saved_regs -= g->length; |
9ef06443 VM |
1460 | for (i = 0; i < g->length; i++) |
1461 | { | |
1462 | regs [i + g->start_reg] = 1; | |
1463 | regs [i + l->start_reg] = -1; | |
1464 | regs_ever_live [i + l->start_reg] = 1; | |
1465 | } | |
1466 | g++; | |
1467 | l++; | |
1468 | gnw--; | |
1469 | lnw--; | |
ba8ab355 | 1470 | } |
9ef06443 VM |
1471 | else if (g->length > l->length) |
1472 | gnw = i960_split_reg_group (g, gnw, l->length); | |
1473 | else | |
1474 | lnw = i960_split_reg_group (l, lnw, g->length); | |
ba8ab355 JW |
1475 | } |
1476 | ||
fca097e7 | 1477 | actual_fsize = compute_frame_size (size) + 4 * n_remaining_saved_regs; |
ba8ab355 JW |
1478 | #if 0 |
1479 | /* ??? The 1.2.1 compiler does this also. This is meant to round the frame | |
1480 | size up to the nearest multiple of 16. I don't know whether this is | |
77a02b01 JW |
1481 | necessary, or even desirable. |
1482 | ||
1483 | The frame pointer must be aligned, but the call instruction takes care of | |
1484 | that. If we leave the stack pointer unaligned, we may save a little on | |
1485 | dynamic stack allocation. And we don't lose, at least according to the | |
1486 | i960CA manual. */ | |
ba8ab355 JW |
1487 | actual_fsize = (actual_fsize + 15) & ~0xF; |
1488 | #endif | |
1489 | ||
a157febd GK |
1490 | /* Check stack limit if necessary. */ |
1491 | if (current_function_limit_stack) | |
1492 | { | |
1493 | rtx min_stack = stack_limit_rtx; | |
1494 | if (actual_fsize != 0) | |
1495 | min_stack = plus_constant (stack_limit_rtx, -actual_fsize); | |
1496 | ||
1497 | /* Now, emulate a little bit of reload. We want to turn 'min_stack' | |
1498 | into an arith_operand. Use register 20 as the temporary. */ | |
1499 | if (legitimate_address_p (Pmode, min_stack, 1) | |
1500 | && !arith_operand (min_stack, Pmode)) | |
1501 | { | |
1502 | rtx tmp = gen_rtx_MEM (Pmode, min_stack); | |
1503 | fputs ("\tlda\t", file); | |
1504 | i960_print_operand (file, tmp, 0); | |
1505 | fputs (",r4\n", file); | |
1506 | min_stack = gen_rtx_REG (Pmode, 20); | |
1507 | } | |
1508 | if (arith_operand (min_stack, Pmode)) | |
1509 | { | |
1510 | fputs ("\tcmpo\tsp,", file); | |
1511 | i960_print_operand (file, min_stack, 0); | |
1512 | fputs ("\n\tfaultge.f\n", file); | |
1513 | } | |
1514 | else | |
1515 | warning ("stack limit expression is not supported"); | |
1516 | } | |
1517 | ||
ba8ab355 JW |
1518 | /* Allocate space for register save and locals. */ |
1519 | if (actual_fsize > 0) | |
1520 | { | |
1521 | if (actual_fsize < 32) | |
1522 | fprintf (file, "\taddo %d,sp,sp\n", actual_fsize); | |
1523 | else | |
1524 | fprintf (file, "\tlda\t%d(sp),sp\n", actual_fsize); | |
1525 | } | |
77a02b01 JW |
1526 | |
1527 | /* Take hardware register save area created by the call instruction | |
2ea998c8 | 1528 | into account, but store them before the argument block area. */ |
fca097e7 | 1529 | lvar_size = actual_fsize - compute_frame_size (0) - n_remaining_saved_regs * 4; |
a157febd | 1530 | offset = STARTING_FRAME_OFFSET + lvar_size; |
ba8ab355 | 1531 | /* Save registers on stack if needed. */ |
9ef06443 VM |
1532 | /* ??? Is it worth to use the same algorithm as one for saving |
1533 | global registers in local registers? */ | |
bcf783f4 | 1534 | for (i = 0, j = n_remaining_saved_regs; j > 0 && i < 16; i++) |
ba8ab355 JW |
1535 | { |
1536 | if (regs[i] != -1) | |
1537 | continue; | |
1538 | ||
1539 | nr = 1; | |
1540 | ||
77a02b01 | 1541 | if (i <= 14 && i % 2 == 0 && regs[i+1] == -1 && offset % 2 == 0) |
ba8ab355 JW |
1542 | nr = 2; |
1543 | ||
77a02b01 JW |
1544 | if (nr == 2 && i <= 12 && i % 4 == 0 && regs[i+2] == -1 |
1545 | && offset % 4 == 0) | |
ba8ab355 JW |
1546 | nr = 3; |
1547 | ||
1548 | if (nr == 3 && regs[i+3] == -1) | |
1549 | nr = 4; | |
1550 | ||
1551 | fprintf (file,"\tst%s %s,%d(fp)\n", | |
1552 | ((nr == 4) ? "q" : | |
1553 | (nr == 3) ? "t" : | |
1554 | (nr == 2) ? "l" : ""), | |
77a02b01 | 1555 | reg_names[i], offset); |
ba8ab355 JW |
1556 | sprintf (tmpstr,"\tld%s %d(fp),%s\n", |
1557 | ((nr == 4) ? "q" : | |
1558 | (nr == 3) ? "t" : | |
1559 | (nr == 2) ? "l" : ""), | |
77a02b01 | 1560 | offset, reg_names[i]); |
ba8ab355 JW |
1561 | strcat (epilogue_string, tmpstr); |
1562 | i += nr-1; | |
1563 | j -= nr; | |
77a02b01 | 1564 | offset += nr * 4; |
ba8ab355 JW |
1565 | } |
1566 | ||
bcf783f4 | 1567 | if (actual_fsize == 0) |
ba8ab355 JW |
1568 | return; |
1569 | ||
1570 | fprintf (file, "\t#Prologue stats:\n"); | |
1571 | fprintf (file, "\t# Total Frame Size: %d bytes\n", actual_fsize); | |
1572 | ||
bcf783f4 VM |
1573 | if (lvar_size) |
1574 | fprintf (file, "\t# Local Variable Size: %d bytes\n", lvar_size); | |
1575 | if (n_saved_regs) | |
ba8ab355 | 1576 | fprintf (file, "\t# Register Save Size: %d regs, %d bytes\n", |
bcf783f4 | 1577 | n_saved_regs, n_saved_regs * 4); |
ba8ab355 JW |
1578 | fprintf (file, "\t#End Prologue#\n"); |
1579 | } | |
1580 | ||
7a24dbcf JW |
1581 | /* Output code for the function profiler. */ |
1582 | ||
1583 | void | |
1584 | output_function_profiler (file, labelno) | |
1585 | FILE *file; | |
1586 | int labelno; | |
1587 | { | |
1588 | /* The last used parameter register. */ | |
1589 | int last_parm_reg; | |
1590 | int i, j, increment; | |
c25d3f20 JW |
1591 | int varargs_stdarg_function |
1592 | = VARARGS_STDARG_FUNCTION (current_function_decl); | |
7a24dbcf JW |
1593 | |
1594 | /* Figure out the last used parameter register. The proper thing to do | |
1595 | is to walk incoming args of the function. A function might have live | |
1596 | parameter registers even if it has no incoming args. Note that we | |
1597 | don't have to save parameter registers g8 to g11 because they are | |
1598 | call preserved. */ | |
1599 | ||
1600 | /* See also output_function_prologue, which tries to use local registers | |
1601 | for preserved call-saved global registers. */ | |
1602 | ||
1603 | for (last_parm_reg = 7; | |
1604 | last_parm_reg >= 0 && ! regs_ever_live[last_parm_reg]; | |
1605 | last_parm_reg--) | |
1606 | ; | |
1607 | ||
1608 | /* Save parameter registers in regs r4 (20) to r11 (27). */ | |
1609 | ||
1610 | for (i = 0, j = 4; i <= last_parm_reg; i += increment, j += increment) | |
1611 | { | |
1612 | if (i % 4 == 0 && (last_parm_reg - i) >= 3) | |
1613 | increment = 4; | |
1614 | else if (i % 4 == 0 && (last_parm_reg - i) >= 2) | |
1615 | increment = 3; | |
1616 | else if (i % 2 == 0 && (last_parm_reg - i) >= 1) | |
1617 | increment = 2; | |
1618 | else | |
1619 | increment = 1; | |
1620 | ||
1621 | fprintf (file, "\tmov%s g%d,r%d\n", | |
1622 | (increment == 4 ? "q" : increment == 3 ? "t" | |
1623 | : increment == 2 ? "l": ""), i, j); | |
1624 | } | |
1625 | ||
1626 | /* If this function uses the arg pointer, then save it in r3 and then | |
1627 | set it to zero. */ | |
1628 | ||
c25d3f20 | 1629 | if (current_function_args_size != 0 || varargs_stdarg_function) |
bfc965cf | 1630 | fprintf (file, "\tmov g14,r3\n\tmov 0,g14\n"); |
7a24dbcf JW |
1631 | |
1632 | /* Load location address into g0 and call mcount. */ | |
1633 | ||
1634 | fprintf (file, "\tlda\tLP%d,g0\n\tcallx\tmcount\n", labelno); | |
1635 | ||
1636 | /* If this function uses the arg pointer, restore it. */ | |
1637 | ||
c25d3f20 | 1638 | if (current_function_args_size != 0 || varargs_stdarg_function) |
bfc965cf | 1639 | fprintf (file, "\tmov r3,g14\n"); |
7a24dbcf JW |
1640 | |
1641 | /* Restore parameter registers. */ | |
1642 | ||
1643 | for (i = 0, j = 4; i <= last_parm_reg; i += increment, j += increment) | |
1644 | { | |
1645 | if (i % 4 == 0 && (last_parm_reg - i) >= 3) | |
1646 | increment = 4; | |
1647 | else if (i % 4 == 0 && (last_parm_reg - i) >= 2) | |
1648 | increment = 3; | |
1649 | else if (i % 2 == 0 && (last_parm_reg - i) >= 1) | |
1650 | increment = 2; | |
1651 | else | |
1652 | increment = 1; | |
1653 | ||
1654 | fprintf (file, "\tmov%s r%d,g%d\n", | |
1655 | (increment == 4 ? "q" : increment == 3 ? "t" | |
1656 | : increment == 2 ? "l": ""), j, i); | |
1657 | } | |
1658 | } | |
1659 | ||
ba8ab355 JW |
1660 | /* Output code for the function epilogue. */ |
1661 | ||
1662 | void | |
1663 | i960_function_epilogue (file, size) | |
1664 | FILE *file; | |
3d2cfac6 | 1665 | unsigned int size ATTRIBUTE_UNUSED; |
ba8ab355 JW |
1666 | { |
1667 | if (i960_leaf_ret_reg >= 0) | |
1668 | { | |
c3c7ea1f | 1669 | fprintf (file, "Li960R%d: ret\n", ret_label); |
ba8ab355 JW |
1670 | return; |
1671 | } | |
1672 | ||
1673 | if (*epilogue_string == 0) | |
1674 | { | |
1675 | register rtx tmp; | |
1676 | ||
1677 | /* Emit a return insn, but only if control can fall through to here. */ | |
1678 | ||
1679 | tmp = get_last_insn (); | |
1680 | while (tmp) | |
1681 | { | |
1682 | if (GET_CODE (tmp) == BARRIER) | |
1683 | return; | |
1684 | if (GET_CODE (tmp) == CODE_LABEL) | |
1685 | break; | |
1686 | if (GET_CODE (tmp) == JUMP_INSN) | |
1687 | { | |
1688 | if (GET_CODE (PATTERN (tmp)) == RETURN) | |
1689 | return; | |
1690 | break; | |
1691 | } | |
1692 | if (GET_CODE (tmp) == NOTE) | |
1693 | { | |
1694 | tmp = PREV_INSN (tmp); | |
1695 | continue; | |
1696 | } | |
1697 | break; | |
1698 | } | |
c3c7ea1f | 1699 | fprintf (file, "Li960R%d: ret\n", ret_label); |
ba8ab355 JW |
1700 | return; |
1701 | } | |
1702 | ||
c3c7ea1f | 1703 | fprintf (file, "Li960R%d:\n", ret_label); |
ba8ab355 JW |
1704 | |
1705 | fprintf (file, "\t#EPILOGUE#\n"); | |
1706 | ||
1707 | /* Output the string created by the prologue which will restore all | |
1708 | registers saved by the prologue. */ | |
1709 | ||
1710 | if (epilogue_string[0] != '\0') | |
1711 | fprintf (file, "%s", epilogue_string); | |
1712 | ||
4c876b4f RK |
1713 | /* Must clear g14 on return if this function set it. |
1714 | Only varargs/stdarg functions modify g14. */ | |
ba8ab355 | 1715 | |
4c876b4f | 1716 | if (VARARGS_STDARG_FUNCTION (current_function_decl)) |
ba8ab355 JW |
1717 | fprintf (file, "\tmov 0,g14\n"); |
1718 | ||
1719 | fprintf (file, "\tret\n"); | |
1720 | fprintf (file, "\t#End Epilogue#\n"); | |
1721 | } | |
1722 | ||
1723 | /* Output code for a call insn. */ | |
1724 | ||
3d2cfac6 | 1725 | const char * |
fda792c6 JW |
1726 | i960_output_call_insn (target, argsize_rtx, arg_pointer, insn) |
1727 | register rtx target, argsize_rtx, arg_pointer, insn; | |
ba8ab355 | 1728 | { |
ba8ab355 JW |
1729 | int argsize = INTVAL (argsize_rtx); |
1730 | rtx nexti = next_real_insn (insn); | |
fda792c6 | 1731 | rtx operands[2]; |
c25d3f20 JW |
1732 | int varargs_stdarg_function |
1733 | = VARARGS_STDARG_FUNCTION (current_function_decl); | |
ba8ab355 JW |
1734 | |
1735 | operands[0] = target; | |
83f49630 | 1736 | operands[1] = arg_pointer; |
83f49630 | 1737 | |
c25d3f20 | 1738 | if (current_function_args_size != 0 || varargs_stdarg_function) |
fda792c6 | 1739 | output_asm_insn ("mov g14,r3", operands); |
83f49630 JW |
1740 | |
1741 | if (argsize > 48) | |
1742 | output_asm_insn ("lda %a1,g14", operands); | |
c25d3f20 | 1743 | else if (current_function_args_size != 0 || varargs_stdarg_function) |
83f49630 | 1744 | output_asm_insn ("mov 0,g14", operands); |
ba8ab355 | 1745 | |
76542a00 JW |
1746 | /* The code used to assume that calls to SYMBOL_REFs could not be more |
1747 | than 24 bits away (b vs bx, callj vs callx). This is not true. This | |
1748 | feature is now implemented by relaxing in the GNU linker. It can convert | |
1749 | bx to b if in range, and callx to calls/call/balx/bal as appropriate. */ | |
ba8ab355 JW |
1750 | |
1751 | /* Nexti could be zero if the called routine is volatile. */ | |
1752 | if (optimize && (*epilogue_string == 0) && argsize == 0 && tail_call_ok | |
1753 | && (nexti == 0 || GET_CODE (PATTERN (nexti)) == RETURN)) | |
1754 | { | |
1755 | /* Delete following return insn. */ | |
1756 | if (nexti && no_labels_between_p (insn, nexti)) | |
1757 | delete_insn (nexti); | |
76542a00 | 1758 | output_asm_insn ("bx %0", operands); |
ba8ab355 JW |
1759 | return "# notreached"; |
1760 | } | |
1761 | ||
76542a00 | 1762 | output_asm_insn ("callx %0", operands); |
83f49630 | 1763 | |
4c876b4f RK |
1764 | /* If the caller sets g14 to the address of the argblock, then the caller |
1765 | must clear it after the return. */ | |
1766 | ||
c25d3f20 | 1767 | if (current_function_args_size != 0 || varargs_stdarg_function) |
fda792c6 | 1768 | output_asm_insn ("mov r3,g14", operands); |
4c876b4f RK |
1769 | else if (argsize > 48) |
1770 | output_asm_insn ("mov 0,g14", operands); | |
83f49630 | 1771 | |
ba8ab355 JW |
1772 | return ""; |
1773 | } | |
1774 | ||
1775 | /* Output code for a return insn. */ | |
1776 | ||
3d2cfac6 | 1777 | const char * |
ba8ab355 JW |
1778 | i960_output_ret_insn (insn) |
1779 | register rtx insn; | |
1780 | { | |
1781 | static char lbuf[20]; | |
1782 | ||
1783 | if (*epilogue_string != 0) | |
1784 | { | |
1785 | if (! TARGET_CODE_ALIGN && next_real_insn (insn) == 0) | |
1786 | return ""; | |
1787 | ||
c3c7ea1f | 1788 | sprintf (lbuf, "b Li960R%d", ret_label); |
ba8ab355 JW |
1789 | return lbuf; |
1790 | } | |
1791 | ||
4c876b4f RK |
1792 | /* Must clear g14 on return if this function set it. |
1793 | Only varargs/stdarg functions modify g14. */ | |
1794 | ||
1795 | if (VARARGS_STDARG_FUNCTION (current_function_decl)) | |
ba8ab355 JW |
1796 | output_asm_insn ("mov 0,g14", 0); |
1797 | ||
1798 | if (i960_leaf_ret_reg >= 0) | |
1799 | { | |
1800 | sprintf (lbuf, "bx (%s)", reg_names[i960_leaf_ret_reg]); | |
1801 | return lbuf; | |
1802 | } | |
1803 | return "ret"; | |
1804 | } | |
1805 | \f | |
ba8ab355 JW |
1806 | /* Print the operand represented by rtx X formatted by code CODE. */ |
1807 | ||
1808 | void | |
1809 | i960_print_operand (file, x, code) | |
1810 | FILE *file; | |
1811 | rtx x; | |
3d2cfac6 | 1812 | int code; |
ba8ab355 | 1813 | { |
eb9c1bb6 | 1814 | enum rtx_code rtxcode = x ? GET_CODE (x) : NIL; |
ba8ab355 JW |
1815 | |
1816 | if (rtxcode == REG) | |
1817 | { | |
1818 | switch (code) | |
1819 | { | |
1820 | case 'D': | |
3a89bbcb | 1821 | /* Second reg of a double or quad. */ |
ba8ab355 JW |
1822 | fprintf (file, "%s", reg_names[REGNO (x)+1]); |
1823 | break; | |
1824 | ||
3a89bbcb RK |
1825 | case 'E': |
1826 | /* Third reg of a quad. */ | |
1827 | fprintf (file, "%s", reg_names[REGNO (x)+2]); | |
1828 | break; | |
1829 | ||
1830 | case 'F': | |
1831 | /* Fourth reg of a quad. */ | |
1832 | fprintf (file, "%s", reg_names[REGNO (x)+3]); | |
1833 | break; | |
1834 | ||
ba8ab355 JW |
1835 | case 0: |
1836 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
1837 | break; | |
1838 | ||
1839 | default: | |
1840 | abort (); | |
1841 | } | |
1842 | return; | |
1843 | } | |
1844 | else if (rtxcode == MEM) | |
1845 | { | |
1846 | output_address (XEXP (x, 0)); | |
1847 | return; | |
1848 | } | |
1849 | else if (rtxcode == CONST_INT) | |
1850 | { | |
f20200f4 TG |
1851 | HOST_WIDE_INT val = INTVAL (x); |
1852 | if (code == 'C') | |
1853 | val = ~val; | |
1854 | if (val > 9999 || val < -999) | |
1855 | fprintf (file, "0x%x", val); | |
ba8ab355 | 1856 | else |
f20200f4 | 1857 | fprintf (file, "%d", val); |
ba8ab355 JW |
1858 | return; |
1859 | } | |
1860 | else if (rtxcode == CONST_DOUBLE) | |
1861 | { | |
ca01dc12 TG |
1862 | REAL_VALUE_TYPE d; |
1863 | char dstr[30]; | |
ba8ab355 | 1864 | |
ca01dc12 | 1865 | if (x == CONST0_RTX (GET_MODE (x))) |
ba8ab355 JW |
1866 | { |
1867 | fprintf (file, "0f0.0"); | |
1868 | return; | |
1869 | } | |
ca01dc12 | 1870 | else if (x == CONST1_RTX (GET_MODE (x))) |
ba8ab355 JW |
1871 | { |
1872 | fprintf (file, "0f1.0"); | |
1873 | return; | |
1874 | } | |
1875 | ||
ba8ab355 | 1876 | REAL_VALUE_FROM_CONST_DOUBLE (d, x); |
ca01dc12 TG |
1877 | REAL_VALUE_TO_DECIMAL (d, "%#g", dstr); |
1878 | fprintf (file, "0f%s", dstr); | |
ba8ab355 JW |
1879 | return; |
1880 | } | |
1881 | ||
1882 | switch(code) | |
1883 | { | |
1884 | case 'B': | |
1885 | /* Branch or jump, depending on assembler. */ | |
1886 | if (TARGET_ASM_COMPAT) | |
1887 | fputs ("j", file); | |
1888 | else | |
1889 | fputs ("b", file); | |
1890 | break; | |
1891 | ||
1892 | case 'S': | |
1893 | /* Sign of condition. */ | |
1894 | if ((rtxcode == EQ) || (rtxcode == NE) || (rtxcode == GTU) | |
1895 | || (rtxcode == LTU) || (rtxcode == GEU) || (rtxcode == LEU)) | |
1896 | fputs ("o", file); | |
1897 | else if ((rtxcode == GT) || (rtxcode == LT) | |
1898 | || (rtxcode == GE) || (rtxcode == LE)) | |
1899 | fputs ("i", file); | |
1900 | else | |
1901 | abort(); | |
1902 | break; | |
1903 | ||
1904 | case 'I': | |
1905 | /* Inverted condition. */ | |
1906 | rtxcode = reverse_condition (rtxcode); | |
1907 | goto normal; | |
1908 | ||
1909 | case 'X': | |
1910 | /* Inverted condition w/ reversed operands. */ | |
1911 | rtxcode = reverse_condition (rtxcode); | |
1912 | /* Fallthrough. */ | |
1913 | ||
1914 | case 'R': | |
1915 | /* Reversed operand condition. */ | |
1916 | rtxcode = swap_condition (rtxcode); | |
1917 | /* Fallthrough. */ | |
1918 | ||
1919 | case 'C': | |
1920 | /* Normal condition. */ | |
1921 | normal: | |
1922 | if (rtxcode == EQ) { fputs ("e", file); return; } | |
1923 | else if (rtxcode == NE) { fputs ("ne", file); return; } | |
1924 | else if (rtxcode == GT) { fputs ("g", file); return; } | |
1925 | else if (rtxcode == GTU) { fputs ("g", file); return; } | |
1926 | else if (rtxcode == LT) { fputs ("l", file); return; } | |
1927 | else if (rtxcode == LTU) { fputs ("l", file); return; } | |
1928 | else if (rtxcode == GE) { fputs ("ge", file); return; } | |
1929 | else if (rtxcode == GEU) { fputs ("ge", file); return; } | |
1930 | else if (rtxcode == LE) { fputs ("le", file); return; } | |
1931 | else if (rtxcode == LEU) { fputs ("le", file); return; } | |
1932 | else abort (); | |
1933 | break; | |
1934 | ||
eb9c1bb6 RH |
1935 | case '+': |
1936 | /* For conditional branches, substitute ".t" or ".f". */ | |
1937 | if (TARGET_BRANCH_PREDICT) | |
1938 | { | |
1939 | x = find_reg_note (current_output_insn, REG_BR_PROB, 0); | |
1940 | if (x) | |
1941 | { | |
1942 | int pred_val = INTVAL (XEXP (x, 0)); | |
1943 | fputs ((pred_val < REG_BR_PROB_BASE / 2 ? ".f" : ".t"), file); | |
1944 | } | |
1945 | } | |
1946 | break; | |
1947 | ||
ba8ab355 JW |
1948 | case 0: |
1949 | output_addr_const (file, x); | |
1950 | break; | |
1951 | ||
1952 | default: | |
1953 | abort (); | |
1954 | } | |
1955 | ||
1956 | return; | |
1957 | } | |
1958 | \f | |
1959 | /* Print a memory address as an operand to reference that memory location. | |
1960 | ||
1961 | This is exactly the same as legitimate_address_p, except that it the prints | |
1962 | addresses instead of recognizing them. */ | |
1963 | ||
1964 | void | |
1965 | i960_print_operand_addr (file, addr) | |
1966 | FILE *file; | |
1967 | register rtx addr; | |
1968 | { | |
1969 | rtx breg, ireg; | |
1970 | rtx scale, offset; | |
1971 | ||
1972 | ireg = 0; | |
1973 | breg = 0; | |
1974 | offset = 0; | |
1975 | scale = const1_rtx; | |
1976 | ||
1977 | if (GET_CODE (addr) == REG) | |
1978 | breg = addr; | |
1979 | else if (CONSTANT_P (addr)) | |
1980 | offset = addr; | |
1981 | else if (GET_CODE (addr) == PLUS) | |
1982 | { | |
1983 | rtx op0, op1; | |
1984 | ||
1985 | op0 = XEXP (addr, 0); | |
1986 | op1 = XEXP (addr, 1); | |
1987 | ||
1988 | if (GET_CODE (op0) == REG) | |
1989 | { | |
1990 | breg = op0; | |
1991 | if (GET_CODE (op1) == REG) | |
1992 | ireg = op1; | |
1993 | else if (CONSTANT_P (op1)) | |
1994 | offset = op1; | |
1995 | else | |
1996 | abort (); | |
1997 | } | |
1998 | else if (GET_CODE (op0) == PLUS) | |
1999 | { | |
2000 | if (GET_CODE (XEXP (op0, 0)) == MULT) | |
2001 | { | |
2002 | ireg = XEXP (XEXP (op0, 0), 0); | |
2003 | scale = XEXP (XEXP (op0, 0), 1); | |
2004 | if (GET_CODE (XEXP (op0, 1)) == REG) | |
2005 | { | |
2006 | breg = XEXP (op0, 1); | |
2007 | offset = op1; | |
2008 | } | |
2009 | else | |
2010 | abort (); | |
2011 | } | |
2012 | else if (GET_CODE (XEXP (op0, 0)) == REG) | |
2013 | { | |
2014 | breg = XEXP (op0, 0); | |
2015 | if (GET_CODE (XEXP (op0, 1)) == REG) | |
2016 | { | |
2017 | ireg = XEXP (op0, 1); | |
2018 | offset = op1; | |
2019 | } | |
2020 | else | |
2021 | abort (); | |
2022 | } | |
2023 | else | |
2024 | abort (); | |
2025 | } | |
2026 | else if (GET_CODE (op0) == MULT) | |
2027 | { | |
2028 | ireg = XEXP (op0, 0); | |
2029 | scale = XEXP (op0, 1); | |
2030 | if (GET_CODE (op1) == REG) | |
2031 | breg = op1; | |
2032 | else if (CONSTANT_P (op1)) | |
2033 | offset = op1; | |
2034 | else | |
2035 | abort (); | |
2036 | } | |
2037 | else | |
2038 | abort (); | |
2039 | } | |
2040 | else if (GET_CODE (addr) == MULT) | |
2041 | { | |
a2f30f14 | 2042 | ireg = XEXP (addr, 0); |
ba8ab355 JW |
2043 | scale = XEXP (addr, 1); |
2044 | } | |
2045 | else | |
2046 | abort (); | |
2047 | ||
2048 | if (offset) | |
2049 | output_addr_const (file, offset); | |
2050 | if (breg) | |
2051 | fprintf (file, "(%s)", reg_names[REGNO (breg)]); | |
2052 | if (ireg) | |
2053 | fprintf (file, "[%s*%d]", reg_names[REGNO (ireg)], INTVAL (scale)); | |
2054 | } | |
2055 | \f | |
2056 | /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression | |
2057 | that is a valid memory address for an instruction. | |
2058 | The MODE argument is the machine mode for the MEM expression | |
2059 | that wants to use this address. | |
2060 | ||
2061 | On 80960, legitimate addresses are: | |
2062 | base ld (g0),r0 | |
2063 | disp (12 or 32 bit) ld foo,r0 | |
2064 | base + index ld (g0)[g1*1],r0 | |
2065 | base + displ ld 0xf00(g0),r0 | |
2066 | base + index*scale + displ ld 0xf00(g0)[g1*4],r0 | |
2067 | index*scale + base ld (g0)[g1*4],r0 | |
2068 | index*scale + displ ld 0xf00[g1*4],r0 | |
2069 | index*scale ld [g1*4],r0 | |
2070 | index + base + displ ld 0xf00(g0)[g1*1],r0 | |
2071 | ||
2072 | In each case, scale can be 1, 2, 4, 8, or 16. */ | |
2073 | ||
2074 | /* This is exactly the same as i960_print_operand_addr, except that | |
2075 | it recognizes addresses instead of printing them. | |
2076 | ||
2077 | It only recognizes address in canonical form. LEGITIMIZE_ADDRESS should | |
2078 | convert common non-canonical forms to canonical form so that they will | |
2079 | be recognized. */ | |
2080 | ||
0a56ad62 JW |
2081 | /* These two macros allow us to accept either a REG or a SUBREG anyplace |
2082 | where a register is valid. */ | |
2083 | ||
2084 | #define RTX_OK_FOR_BASE_P(X, STRICT) \ | |
2085 | ((GET_CODE (X) == REG \ | |
2086 | && (STRICT ? REG_OK_FOR_BASE_P_STRICT (X) : REG_OK_FOR_BASE_P (X))) \ | |
2087 | || (GET_CODE (X) == SUBREG \ | |
2088 | && GET_CODE (SUBREG_REG (X)) == REG \ | |
2089 | && (STRICT ? REG_OK_FOR_BASE_P_STRICT (SUBREG_REG (X)) \ | |
2090 | : REG_OK_FOR_BASE_P (SUBREG_REG (X))))) | |
2091 | ||
2092 | #define RTX_OK_FOR_INDEX_P(X, STRICT) \ | |
2093 | ((GET_CODE (X) == REG \ | |
2094 | && (STRICT ? REG_OK_FOR_INDEX_P_STRICT (X) : REG_OK_FOR_INDEX_P (X)))\ | |
2095 | || (GET_CODE (X) == SUBREG \ | |
2096 | && GET_CODE (SUBREG_REG (X)) == REG \ | |
2097 | && (STRICT ? REG_OK_FOR_INDEX_P_STRICT (SUBREG_REG (X)) \ | |
2098 | : REG_OK_FOR_INDEX_P (SUBREG_REG (X))))) | |
2099 | ||
ba8ab355 JW |
2100 | int |
2101 | legitimate_address_p (mode, addr, strict) | |
3d2cfac6 | 2102 | enum machine_mode mode ATTRIBUTE_UNUSED; |
ba8ab355 JW |
2103 | register rtx addr; |
2104 | int strict; | |
2105 | { | |
0a56ad62 JW |
2106 | if (RTX_OK_FOR_BASE_P (addr, strict)) |
2107 | return 1; | |
ba8ab355 JW |
2108 | else if (CONSTANT_P (addr)) |
2109 | return 1; | |
2110 | else if (GET_CODE (addr) == PLUS) | |
2111 | { | |
2112 | rtx op0, op1; | |
2113 | ||
2114 | if (! TARGET_COMPLEX_ADDR && ! reload_completed) | |
2115 | return 0; | |
2116 | ||
2117 | op0 = XEXP (addr, 0); | |
2118 | op1 = XEXP (addr, 1); | |
2119 | ||
0a56ad62 | 2120 | if (RTX_OK_FOR_BASE_P (op0, strict)) |
ba8ab355 | 2121 | { |
0a56ad62 JW |
2122 | if (RTX_OK_FOR_INDEX_P (op1, strict)) |
2123 | return 1; | |
ba8ab355 JW |
2124 | else if (CONSTANT_P (op1)) |
2125 | return 1; | |
2126 | else | |
2127 | return 0; | |
2128 | } | |
2129 | else if (GET_CODE (op0) == PLUS) | |
2130 | { | |
2131 | if (GET_CODE (XEXP (op0, 0)) == MULT) | |
2132 | { | |
0a56ad62 | 2133 | if (! (RTX_OK_FOR_INDEX_P (XEXP (XEXP (op0, 0), 0), strict) |
ba8ab355 JW |
2134 | && SCALE_TERM_P (XEXP (XEXP (op0, 0), 1)))) |
2135 | return 0; | |
2136 | ||
0a56ad62 JW |
2137 | if (RTX_OK_FOR_BASE_P (XEXP (op0, 1), strict) |
2138 | && CONSTANT_P (op1)) | |
2139 | return 1; | |
ba8ab355 JW |
2140 | else |
2141 | return 0; | |
2142 | } | |
0a56ad62 | 2143 | else if (RTX_OK_FOR_BASE_P (XEXP (op0, 0), strict)) |
ba8ab355 | 2144 | { |
0a56ad62 JW |
2145 | if (RTX_OK_FOR_INDEX_P (XEXP (op0, 1), strict) |
2146 | && CONSTANT_P (op1)) | |
2147 | return 1; | |
ba8ab355 JW |
2148 | else |
2149 | return 0; | |
2150 | } | |
2151 | else | |
2152 | return 0; | |
2153 | } | |
2154 | else if (GET_CODE (op0) == MULT) | |
2155 | { | |
0a56ad62 | 2156 | if (! (RTX_OK_FOR_INDEX_P (XEXP (op0, 0), strict) |
ba8ab355 JW |
2157 | && SCALE_TERM_P (XEXP (op0, 1)))) |
2158 | return 0; | |
2159 | ||
0a56ad62 JW |
2160 | if (RTX_OK_FOR_BASE_P (op1, strict)) |
2161 | return 1; | |
ba8ab355 JW |
2162 | else if (CONSTANT_P (op1)) |
2163 | return 1; | |
2164 | else | |
2165 | return 0; | |
2166 | } | |
2167 | else | |
2168 | return 0; | |
2169 | } | |
2170 | else if (GET_CODE (addr) == MULT) | |
2171 | { | |
2172 | if (! TARGET_COMPLEX_ADDR && ! reload_completed) | |
2173 | return 0; | |
2174 | ||
0a56ad62 | 2175 | return (RTX_OK_FOR_INDEX_P (XEXP (addr, 0), strict) |
ba8ab355 JW |
2176 | && SCALE_TERM_P (XEXP (addr, 1))); |
2177 | } | |
2178 | else | |
2179 | return 0; | |
2180 | } | |
2181 | ||
2182 | /* Try machine-dependent ways of modifying an illegitimate address | |
2183 | to be legitimate. If we find one, return the new, valid address. | |
2184 | This macro is used in only one place: `memory_address' in explow.c. | |
2185 | ||
2186 | This converts some non-canonical addresses to canonical form so they | |
2187 | can be recognized. */ | |
2188 | ||
2189 | rtx | |
2190 | legitimize_address (x, oldx, mode) | |
2191 | register rtx x; | |
3d2cfac6 KG |
2192 | register rtx oldx ATTRIBUTE_UNUSED; |
2193 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
ba8ab355 JW |
2194 | { |
2195 | if (GET_CODE (x) == SYMBOL_REF) | |
2196 | { | |
2197 | abort (); | |
2198 | x = copy_to_reg (x); | |
2199 | } | |
2200 | ||
2201 | if (! TARGET_COMPLEX_ADDR && ! reload_completed) | |
2202 | return x; | |
2203 | ||
2204 | /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const))) | |
2205 | into (plus (plus (mult (reg) (const)) (reg)) (const)). This can be | |
2206 | created by virtual register instantiation, register elimination, and | |
2207 | similar optimizations. */ | |
2208 | if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT | |
2209 | && GET_CODE (XEXP (x, 1)) == PLUS) | |
c5c76735 JL |
2210 | x = gen_rtx_PLUS (Pmode, |
2211 | gen_rtx_PLUS (Pmode, XEXP (x, 0), XEXP (XEXP (x, 1), 0)), | |
2212 | XEXP (XEXP (x, 1), 1)); | |
ba8ab355 JW |
2213 | |
2214 | /* Canonicalize (plus (plus (mult (reg) (const)) (plus (reg) (const))) const) | |
2215 | into (plus (plus (mult (reg) (const)) (reg)) (const)). */ | |
2216 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS | |
2217 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT | |
2218 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS | |
2219 | && CONSTANT_P (XEXP (x, 1))) | |
2220 | { | |
2221 | rtx constant, other; | |
2222 | ||
2223 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
2224 | { | |
2225 | constant = XEXP (x, 1); | |
2226 | other = XEXP (XEXP (XEXP (x, 0), 1), 1); | |
2227 | } | |
2228 | else if (GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 1)) == CONST_INT) | |
2229 | { | |
2230 | constant = XEXP (XEXP (XEXP (x, 0), 1), 1); | |
2231 | other = XEXP (x, 1); | |
2232 | } | |
2233 | else | |
2234 | constant = 0; | |
2235 | ||
2236 | if (constant) | |
c5c76735 JL |
2237 | x = gen_rtx_PLUS (Pmode, |
2238 | gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0), | |
2239 | XEXP (XEXP (XEXP (x, 0), 1), 0)), | |
2240 | plus_constant (other, INTVAL (constant))); | |
ba8ab355 JW |
2241 | } |
2242 | ||
2243 | return x; | |
2244 | } | |
2245 | \f | |
2246 | #if 0 | |
2247 | /* Return the most stringent alignment that we are willing to consider | |
2248 | objects of size SIZE and known alignment ALIGN as having. */ | |
2249 | ||
2250 | int | |
2251 | i960_alignment (size, align) | |
2252 | int size; | |
2253 | int align; | |
2254 | { | |
2255 | int i; | |
2256 | ||
2257 | if (! TARGET_STRICT_ALIGN) | |
2258 | if (TARGET_IC_COMPAT2_0 || align >= 4) | |
2259 | { | |
2260 | i = i960_object_bytes_bitalign (size) / BITS_PER_UNIT; | |
2261 | if (i > align) | |
2262 | align = i; | |
2263 | } | |
2264 | ||
2265 | return align; | |
2266 | } | |
2267 | #endif | |
2268 | \f | |
ba8ab355 | 2269 | |
2129b081 JW |
2270 | int |
2271 | hard_regno_mode_ok (regno, mode) | |
2272 | int regno; | |
2273 | enum machine_mode mode; | |
2274 | { | |
2275 | if (regno < 32) | |
2276 | { | |
2277 | switch (mode) | |
2278 | { | |
2279 | case CCmode: case CC_UNSmode: case CC_CHKmode: | |
2280 | return 0; | |
ba8ab355 | 2281 | |
2129b081 JW |
2282 | case DImode: case DFmode: |
2283 | return (regno & 1) == 0; | |
ba8ab355 | 2284 | |
2129b081 JW |
2285 | case TImode: case XFmode: |
2286 | return (regno & 3) == 0; | |
ba8ab355 | 2287 | |
2129b081 JW |
2288 | default: |
2289 | return 1; | |
2290 | } | |
2291 | } | |
2292 | else if (regno >= 32 && regno < 36) | |
2293 | { | |
2294 | switch (mode) | |
2295 | { | |
2296 | case SFmode: case DFmode: case XFmode: | |
2297 | case SCmode: case DCmode: | |
2298 | return 1; | |
ba8ab355 | 2299 | |
2129b081 JW |
2300 | default: |
2301 | return 0; | |
2302 | } | |
2303 | } | |
2304 | else if (regno == 36) | |
2305 | { | |
2306 | switch (mode) | |
2307 | { | |
2308 | case CCmode: case CC_UNSmode: case CC_CHKmode: | |
2309 | return 1; | |
ba8ab355 | 2310 | |
2129b081 JW |
2311 | default: |
2312 | return 0; | |
2313 | } | |
2314 | } | |
2315 | else if (regno == 37) | |
2316 | return 0; | |
ba8ab355 | 2317 | |
2129b081 JW |
2318 | abort (); |
2319 | } | |
ba8ab355 JW |
2320 | |
2321 | \f | |
2322 | /* Return the minimum alignment of an expression rtx X in bytes. This takes | |
2323 | advantage of machine specific facts, such as knowing that the frame pointer | |
2324 | is always 16 byte aligned. */ | |
2325 | ||
2326 | int | |
2327 | i960_expr_alignment (x, size) | |
2328 | rtx x; | |
2329 | int size; | |
2330 | { | |
2331 | int align = 1; | |
2332 | ||
2333 | if (x == 0) | |
2334 | return 1; | |
2335 | ||
2336 | switch (GET_CODE(x)) | |
2337 | { | |
2338 | case CONST_INT: | |
2339 | align = INTVAL(x); | |
2340 | ||
2341 | if ((align & 0xf) == 0) | |
2342 | align = 16; | |
2343 | else if ((align & 0x7) == 0) | |
2344 | align = 8; | |
2345 | else if ((align & 0x3) == 0) | |
2346 | align = 4; | |
2347 | else if ((align & 0x1) == 0) | |
2348 | align = 2; | |
2349 | else | |
2350 | align = 1; | |
2351 | break; | |
2352 | ||
2353 | case PLUS: | |
2354 | align = MIN (i960_expr_alignment (XEXP (x, 0), size), | |
2355 | i960_expr_alignment (XEXP (x, 1), size)); | |
2356 | break; | |
2357 | ||
2358 | case SYMBOL_REF: | |
2359 | /* If this is a valid program, objects are guaranteed to be | |
2360 | correctly aligned for whatever size the reference actually is. */ | |
2361 | align = i960_object_bytes_bitalign (size) / BITS_PER_UNIT; | |
2362 | break; | |
2363 | ||
2364 | case REG: | |
2365 | if (REGNO (x) == FRAME_POINTER_REGNUM) | |
2366 | align = 16; | |
2367 | break; | |
2368 | ||
2369 | case ASHIFT: | |
3d2cfac6 | 2370 | align = i960_expr_alignment (XEXP (x, 0), size); |
ba8ab355 JW |
2371 | |
2372 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
2373 | { | |
2374 | align = align << INTVAL (XEXP (x, 1)); | |
2375 | align = MIN (align, 16); | |
2376 | } | |
2377 | break; | |
2378 | ||
2379 | case MULT: | |
2380 | align = (i960_expr_alignment (XEXP (x, 0), size) * | |
2381 | i960_expr_alignment (XEXP (x, 1), size)); | |
2382 | ||
2383 | align = MIN (align, 16); | |
2384 | break; | |
3d2cfac6 KG |
2385 | default: |
2386 | break; | |
ba8ab355 JW |
2387 | } |
2388 | ||
2389 | return align; | |
2390 | } | |
2391 | ||
2392 | /* Return true if it is possible to reference both BASE and OFFSET, which | |
2393 | have alignment at least as great as 4 byte, as if they had alignment valid | |
2394 | for an object of size SIZE. */ | |
2395 | ||
2396 | int | |
2397 | i960_improve_align (base, offset, size) | |
2398 | rtx base; | |
2399 | rtx offset; | |
2400 | int size; | |
2401 | { | |
2402 | int i, j; | |
2403 | ||
2404 | /* We have at least a word reference to the object, so we know it has to | |
2405 | be aligned at least to 4 bytes. */ | |
2406 | ||
2407 | i = MIN (i960_expr_alignment (base, 4), | |
2408 | i960_expr_alignment (offset, 4)); | |
2409 | ||
2410 | i = MAX (i, 4); | |
2411 | ||
2412 | /* We know the size of the request. If strict align is not enabled, we | |
2413 | can guess that the alignment is OK for the requested size. */ | |
2414 | ||
2415 | if (! TARGET_STRICT_ALIGN) | |
2416 | if ((j = (i960_object_bytes_bitalign (size) / BITS_PER_UNIT)) > i) | |
2417 | i = j; | |
2418 | ||
2419 | return (i >= size); | |
2420 | } | |
2421 | ||
2422 | /* Return true if it is possible to access BASE and OFFSET, which have 4 byte | |
2423 | (SImode) alignment as if they had 16 byte (TImode) alignment. */ | |
2424 | ||
2425 | int | |
2426 | i960_si_ti (base, offset) | |
2427 | rtx base; | |
2428 | rtx offset; | |
2429 | { | |
2430 | return i960_improve_align (base, offset, 16); | |
2431 | } | |
2432 | ||
2433 | /* Return true if it is possible to access BASE and OFFSET, which have 4 byte | |
2434 | (SImode) alignment as if they had 8 byte (DImode) alignment. */ | |
2435 | ||
2436 | int | |
2437 | i960_si_di (base, offset) | |
2438 | rtx base; | |
2439 | rtx offset; | |
2440 | { | |
2441 | return i960_improve_align (base, offset, 8); | |
2442 | } | |
2443 | \f | |
2444 | /* Return raw values of size and alignment (in words) for the data | |
2445 | type being accessed. These values will be rounded by the caller. */ | |
2446 | ||
2447 | static void | |
2448 | i960_arg_size_and_align (mode, type, size_out, align_out) | |
2449 | enum machine_mode mode; | |
2450 | tree type; | |
2451 | int *size_out; | |
2452 | int *align_out; | |
2453 | { | |
2454 | int size, align; | |
2455 | ||
2456 | /* Use formal alignment requirements of type being passed, except make | |
2457 | it at least a word. If we don't have a type, this is a library call, | |
2458 | and the parm has to be of scalar type. In this case, consider its | |
2459 | formal alignment requirement to be its size in words. */ | |
2460 | ||
2461 | if (mode == BLKmode) | |
2462 | size = (int_size_in_bytes (type) + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
2463 | else if (mode == VOIDmode) | |
2464 | { | |
2465 | /* End of parm list. */ | |
3a598fbe JL |
2466 | if (type == 0 || TYPE_MODE (type) != VOIDmode) |
2467 | abort (); | |
ba8ab355 JW |
2468 | size = 1; |
2469 | } | |
2470 | else | |
2471 | size = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
2472 | ||
2473 | if (type == 0) | |
280fc31e RK |
2474 | { |
2475 | /* ??? This is a hack to properly correct the alignment of XFmode | |
2476 | values without affecting anything else. */ | |
2477 | if (size == 3) | |
2478 | align = 4; | |
2479 | else | |
2480 | align = size; | |
2481 | } | |
ba8ab355 JW |
2482 | else if (TYPE_ALIGN (type) >= BITS_PER_WORD) |
2483 | align = TYPE_ALIGN (type) / BITS_PER_WORD; | |
2484 | else | |
2485 | align = 1; | |
2486 | ||
2487 | *size_out = size; | |
2488 | *align_out = align; | |
2489 | } | |
2490 | ||
2491 | /* On the 80960 the first 12 args are in registers and the rest are pushed. | |
2492 | Any arg that is bigger than 4 words is placed on the stack and all | |
2493 | subsequent arguments are placed on the stack. | |
2494 | ||
2495 | Additionally, parameters with an alignment requirement stronger than | |
280fc31e RK |
2496 | a word must be aligned appropriately. Note that this means that a |
2497 | 64 bit object with a 32 bit alignment is not 64 bit aligned and may be | |
2498 | passed in an odd/even register pair. */ | |
ba8ab355 JW |
2499 | |
2500 | /* Update CUM to advance past an argument described by MODE and TYPE. */ | |
2501 | ||
2502 | void | |
2503 | i960_function_arg_advance (cum, mode, type, named) | |
2504 | CUMULATIVE_ARGS *cum; | |
2505 | enum machine_mode mode; | |
2506 | tree type; | |
3d2cfac6 | 2507 | int named ATTRIBUTE_UNUSED; |
ba8ab355 JW |
2508 | { |
2509 | int size, align; | |
2510 | ||
2511 | i960_arg_size_and_align (mode, type, &size, &align); | |
2512 | ||
c25d3f20 | 2513 | if (size > 4 || cum->ca_nstackparms != 0 |
025a8875 | 2514 | || (size + ROUND_PARM (cum->ca_nregparms, align)) > NPARM_REGS |
29008b51 | 2515 | || MUST_PASS_IN_STACK (mode, type)) |
b41ac904 DE |
2516 | { |
2517 | /* Indicate that all the registers are in use, even if all are not, | |
2518 | so va_start will compute the right value. */ | |
2519 | cum->ca_nregparms = NPARM_REGS; | |
2520 | cum->ca_nstackparms = ROUND_PARM (cum->ca_nstackparms, align) + size; | |
2521 | } | |
ba8ab355 | 2522 | else |
025a8875 | 2523 | cum->ca_nregparms = ROUND_PARM (cum->ca_nregparms, align) + size; |
ba8ab355 JW |
2524 | } |
2525 | ||
2526 | /* Return the register that the argument described by MODE and TYPE is | |
2527 | passed in, or else return 0 if it is passed on the stack. */ | |
2528 | ||
2529 | rtx | |
2530 | i960_function_arg (cum, mode, type, named) | |
2531 | CUMULATIVE_ARGS *cum; | |
2532 | enum machine_mode mode; | |
2533 | tree type; | |
3d2cfac6 | 2534 | int named ATTRIBUTE_UNUSED; |
ba8ab355 JW |
2535 | { |
2536 | rtx ret; | |
2537 | int size, align; | |
2538 | ||
eb9c1bb6 RH |
2539 | if (mode == VOIDmode) |
2540 | return 0; | |
2541 | ||
ba8ab355 JW |
2542 | i960_arg_size_and_align (mode, type, &size, &align); |
2543 | ||
c25d3f20 | 2544 | if (size > 4 || cum->ca_nstackparms != 0 |
025a8875 | 2545 | || (size + ROUND_PARM (cum->ca_nregparms, align)) > NPARM_REGS |
29008b51 | 2546 | || MUST_PASS_IN_STACK (mode, type)) |
ba8ab355 | 2547 | { |
025a8875 | 2548 | cum->ca_nstackparms = ROUND_PARM (cum->ca_nstackparms, align); |
ba8ab355 JW |
2549 | ret = 0; |
2550 | } | |
2551 | else | |
2552 | { | |
025a8875 | 2553 | cum->ca_nregparms = ROUND_PARM (cum->ca_nregparms, align); |
c5c76735 | 2554 | ret = gen_rtx_REG (mode, cum->ca_nregparms); |
ba8ab355 JW |
2555 | } |
2556 | ||
2557 | return ret; | |
2558 | } | |
ba8ab355 JW |
2559 | \f |
2560 | /* Floating-point support. */ | |
2561 | ||
37aba850 TG |
2562 | void |
2563 | i960_output_long_double (file, value) | |
2564 | FILE *file; | |
2565 | REAL_VALUE_TYPE value; | |
2566 | { | |
2567 | long value_long[3]; | |
2568 | char dstr[30]; | |
2569 | ||
2570 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (value, value_long); | |
2571 | REAL_VALUE_TO_DECIMAL (value, "%.20g", dstr); | |
2572 | ||
2573 | fprintf (file, | |
2574 | "\t.word\t0x%08lx\t\t# %s\n\t.word\t0x%08lx\n\t.word\t0x%08lx\n", | |
2575 | value_long[0], dstr, value_long[1], value_long[2]); | |
2576 | fprintf (file, "\t.word\t0x0\n"); | |
2577 | } | |
2578 | ||
ba8ab355 JW |
2579 | void |
2580 | i960_output_double (file, value) | |
2581 | FILE *file; | |
ca01dc12 | 2582 | REAL_VALUE_TYPE value; |
ba8ab355 | 2583 | { |
bd657ba5 | 2584 | long value_long[2]; |
1aa8bf84 TG |
2585 | char dstr[30]; |
2586 | ||
bd657ba5 | 2587 | REAL_VALUE_TO_TARGET_DOUBLE (value, value_long); |
1aa8bf84 | 2588 | REAL_VALUE_TO_DECIMAL (value, "%.20g", dstr); |
bd657ba5 | 2589 | |
1aa8bf84 TG |
2590 | fprintf (file, "\t.word\t0x%08lx\t\t# %s\n\t.word\t0x%08lx\n", |
2591 | value_long[0], dstr, value_long[1]); | |
ba8ab355 | 2592 | } |
ca01dc12 | 2593 | |
ba8ab355 JW |
2594 | void |
2595 | i960_output_float (file, value) | |
2596 | FILE *file; | |
ca01dc12 | 2597 | REAL_VALUE_TYPE value; |
ba8ab355 | 2598 | { |
bd657ba5 | 2599 | long value_long; |
1aa8bf84 TG |
2600 | char dstr[30]; |
2601 | ||
bd657ba5 | 2602 | REAL_VALUE_TO_TARGET_SINGLE (value, value_long); |
1aa8bf84 | 2603 | REAL_VALUE_TO_DECIMAL (value, "%.12g", dstr); |
bd657ba5 | 2604 | |
1aa8bf84 | 2605 | fprintf (file, "\t.word\t0x%08lx\t\t# %s (float)\n", value_long, dstr); |
ba8ab355 JW |
2606 | } |
2607 | \f | |
2608 | /* Return the number of bits that an object of size N bytes is aligned to. */ | |
2609 | ||
2610 | int | |
2611 | i960_object_bytes_bitalign (n) | |
2612 | int n; | |
2613 | { | |
2614 | if (n > 8) n = 128; | |
2615 | else if (n > 4) n = 64; | |
2616 | else if (n > 2) n = 32; | |
2617 | else if (n > 1) n = 16; | |
2618 | else n = 8; | |
2619 | ||
2620 | return n; | |
2621 | } | |
2622 | ||
c9040e2c ILT |
2623 | /* Compute the alignment for an aggregate type TSIZE. |
2624 | Alignment is MAX (greatest member alignment, | |
2625 | MIN (pragma align, structure size alignment)). */ | |
ba8ab355 JW |
2626 | |
2627 | int | |
2628 | i960_round_align (align, tsize) | |
2629 | int align; | |
2630 | tree tsize; | |
2631 | { | |
c9040e2c | 2632 | int new_align; |
b676e9e2 | 2633 | |
eb9c1bb6 | 2634 | if (! tsize || TREE_CODE (tsize) != INTEGER_CST) |
ba8ab355 JW |
2635 | return align; |
2636 | ||
c9040e2c ILT |
2637 | new_align = i960_object_bytes_bitalign (TREE_INT_CST_LOW (tsize) |
2638 | / BITS_PER_UNIT); | |
2639 | /* Handle #pragma align. */ | |
2640 | if (new_align > i960_maxbitalignment) | |
2641 | new_align = i960_maxbitalignment; | |
2642 | ||
2643 | if (align < new_align) | |
2644 | align = new_align; | |
2645 | ||
ba8ab355 JW |
2646 | return align; |
2647 | } | |
2648 | \f | |
2649 | /* Do any needed setup for a varargs function. For the i960, we must | |
2296cba3 | 2650 | create a register parameter block if one doesn't exist, and then copy |
ba8ab355 JW |
2651 | all register parameters to memory. */ |
2652 | ||
2653 | void | |
2654 | i960_setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl) | |
2655 | CUMULATIVE_ARGS *cum; | |
3d2cfac6 KG |
2656 | enum machine_mode mode ATTRIBUTE_UNUSED; |
2657 | tree type ATTRIBUTE_UNUSED; | |
2658 | int *pretend_size ATTRIBUTE_UNUSED; | |
ba8ab355 JW |
2659 | int no_rtl; |
2660 | { | |
b41ac904 DE |
2661 | /* Note: for a varargs fn with only a va_alist argument, this is 0. */ |
2662 | int first_reg = cum->ca_nregparms; | |
ba8ab355 | 2663 | |
b41ac904 DE |
2664 | /* Copy only unnamed register arguments to memory. If there are |
2665 | any stack parms, there are no unnamed arguments in registers, and | |
2666 | an argument block was already allocated by the caller. | |
2667 | Remember that any arg bigger than 4 words is passed on the stack as | |
2668 | are all subsequent args. | |
2669 | ||
2670 | If there are no stack arguments but there are exactly NPARM_REGS | |
2671 | registers, either there were no extra arguments or the caller | |
2672 | allocated an argument block. */ | |
2673 | ||
2674 | if (cum->ca_nstackparms == 0 && first_reg < NPARM_REGS && !no_rtl) | |
2675 | { | |
2676 | rtx label = gen_label_rtx (); | |
2677 | rtx regblock; | |
2678 | ||
2679 | /* If arg_pointer_rtx == 0, no arguments were passed on the stack | |
2680 | and we need to allocate a chunk to save the registers (if any | |
2681 | arguments were passed on the stack the caller would allocate the | |
2682 | 48 bytes as well). We must allocate all 48 bytes (12*4) because | |
2683 | va_start assumes it. */ | |
2684 | emit_insn (gen_cmpsi (arg_pointer_rtx, const0_rtx)); | |
2685 | emit_jump_insn (gen_bne (label)); | |
c5c76735 JL |
2686 | emit_insn (gen_rtx_SET (VOIDmode, arg_pointer_rtx, |
2687 | stack_pointer_rtx)); | |
2688 | emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx, | |
2689 | memory_address (SImode, | |
2690 | plus_constant (stack_pointer_rtx, | |
2691 | 48)))); | |
b41ac904 DE |
2692 | emit_label (label); |
2693 | ||
2694 | /* ??? Note that we unnecessarily store one extra register for stdarg | |
c5c76735 JL |
2695 | fns. We could optimize this, but it's kept as for now. */ |
2696 | regblock = gen_rtx_MEM (BLKmode, | |
b41ac904 DE |
2697 | plus_constant (arg_pointer_rtx, |
2698 | first_reg * 4)); | |
c2749e2d | 2699 | MEM_ALIAS_SET (regblock) = get_varargs_alias_set (); |
b41ac904 DE |
2700 | move_block_from_reg (first_reg, regblock, |
2701 | NPARM_REGS - first_reg, | |
2702 | (NPARM_REGS - first_reg) * UNITS_PER_WORD); | |
ba8ab355 JW |
2703 | } |
2704 | } | |
2705 | ||
c2749e2d RH |
2706 | /* Define the `__builtin_va_list' type for the ABI. */ |
2707 | ||
2708 | tree | |
2709 | i960_build_va_list () | |
2710 | { | |
2711 | return build_array_type (unsigned_type_node, | |
2712 | build_index_type (size_one_node)); | |
2713 | } | |
2714 | ||
2715 | /* Implement `va_start' for varargs and stdarg. */ | |
2716 | ||
2717 | void | |
2718 | i960_va_start (stdarg_p, valist, nextarg) | |
2719 | int stdarg_p ATTRIBUTE_UNUSED; | |
2720 | tree valist; | |
2721 | rtx nextarg ATTRIBUTE_UNUSED; | |
2722 | { | |
7ab282a5 JW |
2723 | tree s, t, base, num; |
2724 | ||
2725 | /* The array type always decays to a pointer before we get here, so we | |
2726 | can't use ARRAY_REF. */ | |
2727 | base = build1 (INDIRECT_REF, unsigned_type_node, valist); | |
2728 | num = build1 (INDIRECT_REF, unsigned_type_node, | |
2729 | build (PLUS_EXPR, unsigned_type_node, valist, | |
2730 | TYPE_SIZE_UNIT (TREE_TYPE (valist)))); | |
c2749e2d RH |
2731 | |
2732 | s = make_tree (unsigned_type_node, arg_pointer_rtx); | |
7ab282a5 | 2733 | t = build (MODIFY_EXPR, unsigned_type_node, base, s); |
c2749e2d RH |
2734 | TREE_SIDE_EFFECTS (t) = 1; |
2735 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2736 | ||
2737 | s = build_int_2 ((current_function_args_info.ca_nregparms | |
2738 | + current_function_args_info.ca_nstackparms) * 4, 0); | |
7ab282a5 | 2739 | t = build (MODIFY_EXPR, unsigned_type_node, num, s); |
c2749e2d RH |
2740 | TREE_SIDE_EFFECTS (t) = 1; |
2741 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2742 | } | |
2743 | ||
2744 | /* Implement `va_arg'. */ | |
2745 | ||
2746 | rtx | |
2747 | i960_va_arg (valist, type) | |
2748 | tree valist, type; | |
2749 | { | |
2750 | HOST_WIDE_INT siz, ali; | |
2751 | tree base, num, pad, next, this, t1, t2, int48; | |
2752 | rtx addr_rtx; | |
2753 | ||
7ab282a5 JW |
2754 | /* The array type always decays to a pointer before we get here, so we |
2755 | can't use ARRAY_REF. */ | |
2756 | base = build1 (INDIRECT_REF, unsigned_type_node, valist); | |
2757 | num = build1 (INDIRECT_REF, unsigned_type_node, | |
2758 | build (PLUS_EXPR, unsigned_type_node, valist, | |
2759 | TYPE_SIZE_UNIT (TREE_TYPE (valist)))); | |
c2749e2d RH |
2760 | |
2761 | /* Round up sizeof(type) to a word. */ | |
2762 | siz = (int_size_in_bytes (type) + UNITS_PER_WORD - 1) & -UNITS_PER_WORD; | |
2763 | ||
2764 | /* Round up alignment to a word. */ | |
2765 | ali = TYPE_ALIGN (type); | |
2766 | if (ali < BITS_PER_WORD) | |
2767 | ali = BITS_PER_WORD; | |
2768 | ali /= BITS_PER_UNIT; | |
2769 | ||
2770 | /* Align NUM appropriate for the argument. */ | |
2771 | pad = fold (build (PLUS_EXPR, unsigned_type_node, num, | |
2772 | build_int_2 (ali - 1, 0))); | |
2773 | pad = fold (build (BIT_AND_EXPR, unsigned_type_node, pad, | |
2774 | build_int_2 (-ali, -1))); | |
2775 | pad = save_expr (pad); | |
2776 | ||
2777 | /* Increment VPAD past this argument. */ | |
2778 | next = fold (build (PLUS_EXPR, unsigned_type_node, pad, | |
2779 | build_int_2 (siz, 0))); | |
2780 | next = save_expr (next); | |
2781 | ||
2782 | /* Find the offset for the current argument. Mind peculiar overflow | |
2783 | from registers to stack. */ | |
2784 | int48 = build_int_2 (48, 0); | |
2785 | if (siz > 16) | |
2786 | t2 = integer_one_node; | |
2787 | else | |
2788 | t2 = fold (build (GT_EXPR, integer_type_node, next, int48)); | |
2789 | t1 = fold (build (LE_EXPR, integer_type_node, num, int48)); | |
2790 | t1 = fold (build (TRUTH_AND_EXPR, integer_type_node, t1, t2)); | |
2791 | this = fold (build (COND_EXPR, unsigned_type_node, t1, int48, pad)); | |
2792 | ||
2793 | /* Find the address for the current argument. */ | |
2794 | t1 = fold (build (PLUS_EXPR, unsigned_type_node, base, this)); | |
2795 | t1 = build1 (NOP_EXPR, ptr_type_node, t1); | |
2796 | addr_rtx = expand_expr (t1, NULL_RTX, Pmode, EXPAND_NORMAL); | |
2797 | ||
2798 | /* Increment NUM. */ | |
2799 | t1 = build (MODIFY_EXPR, unsigned_type_node, num, next); | |
2800 | TREE_SIDE_EFFECTS (t1) = 1; | |
2801 | expand_expr (t1, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2802 | ||
2803 | return addr_rtx; | |
2804 | } | |
2805 | ||
ba8ab355 JW |
2806 | /* Calculate the final size of the reg parm stack space for the current |
2807 | function, based on how many bytes would be allocated on the stack. */ | |
2808 | ||
2809 | int | |
2810 | i960_final_reg_parm_stack_space (const_size, var_size) | |
2811 | int const_size; | |
2812 | tree var_size; | |
2813 | { | |
2814 | if (var_size || const_size > 48) | |
2815 | return 48; | |
2816 | else | |
2817 | return 0; | |
2818 | } | |
2819 | ||
2820 | /* Calculate the size of the reg parm stack space. This is a bit complicated | |
2821 | on the i960. */ | |
2822 | ||
2823 | int | |
2824 | i960_reg_parm_stack_space (fndecl) | |
2825 | tree fndecl; | |
2826 | { | |
2827 | /* In this case, we are called from emit_library_call, and we don't need | |
2828 | to pretend we have more space for parameters than what's apparent. */ | |
2829 | if (fndecl == 0) | |
2830 | return 0; | |
2831 | ||
2832 | /* In this case, we are called from locate_and_pad_parms when we're | |
2833 | not IN_REGS, so we have an arg block. */ | |
2834 | if (fndecl != current_function_decl) | |
2835 | return 48; | |
2836 | ||
2837 | /* Otherwise, we have an arg block if the current function has more than | |
2838 | 48 bytes of parameters. */ | |
c25d3f20 | 2839 | if (current_function_args_size != 0 || VARARGS_STDARG_FUNCTION (fndecl)) |
ba8ab355 JW |
2840 | return 48; |
2841 | else | |
2842 | return 0; | |
2843 | } | |
2844 | \f | |
2845 | /* Return the register class of a scratch register needed to copy IN into | |
2846 | or out of a register in CLASS in MODE. If it can be done directly, | |
2847 | NO_REGS is returned. */ | |
2848 | ||
2849 | enum reg_class | |
2850 | secondary_reload_class (class, mode, in) | |
2851 | enum reg_class class; | |
2852 | enum machine_mode mode; | |
2853 | rtx in; | |
2854 | { | |
2855 | int regno = -1; | |
2856 | ||
2857 | if (GET_CODE (in) == REG || GET_CODE (in) == SUBREG) | |
2858 | regno = true_regnum (in); | |
2859 | ||
2860 | /* We can place anything into LOCAL_OR_GLOBAL_REGS and can put | |
2861 | LOCAL_OR_GLOBAL_REGS into anything. */ | |
2862 | if (class == LOCAL_OR_GLOBAL_REGS || class == LOCAL_REGS | |
2863 | || class == GLOBAL_REGS || (regno >= 0 && regno < 32)) | |
2864 | return NO_REGS; | |
2865 | ||
2866 | /* We can place any hard register, 0.0, and 1.0 into FP_REGS. */ | |
2867 | if (class == FP_REGS | |
4c1dfa8f | 2868 | && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER) |
ba8ab355 JW |
2869 | || in == CONST0_RTX (mode) || in == CONST1_RTX (mode))) |
2870 | return NO_REGS; | |
2871 | ||
2872 | return LOCAL_OR_GLOBAL_REGS; | |
2873 | } | |
2874 | \f | |
ba8ab355 JW |
2875 | /* Look at the opcode P, and set i96_last_insn_type to indicate which |
2876 | function unit it executed on. */ | |
2877 | ||
2878 | /* ??? This would make more sense as an attribute. */ | |
2879 | ||
2880 | void | |
2881 | i960_scan_opcode (p) | |
3d2cfac6 | 2882 | const char *p; |
ba8ab355 JW |
2883 | { |
2884 | switch (*p) | |
2885 | { | |
2886 | case 'a': | |
2887 | case 'd': | |
2888 | case 'e': | |
2889 | case 'm': | |
2890 | case 'n': | |
2891 | case 'o': | |
2892 | case 'r': | |
2893 | /* Ret is not actually of type REG, but it won't matter, because no | |
2894 | insn will ever follow it. */ | |
2895 | case 'u': | |
2896 | case 'x': | |
2897 | i960_last_insn_type = I_TYPE_REG; | |
2898 | break; | |
2899 | ||
2900 | case 'b': | |
2901 | if (p[1] == 'x' || p[3] == 'x') | |
2902 | i960_last_insn_type = I_TYPE_MEM; | |
2903 | i960_last_insn_type = I_TYPE_CTRL; | |
2904 | break; | |
2905 | ||
2906 | case 'f': | |
2907 | case 't': | |
2908 | i960_last_insn_type = I_TYPE_CTRL; | |
2909 | break; | |
2910 | ||
2911 | case 'c': | |
2912 | if (p[1] == 'a') | |
2913 | { | |
2914 | if (p[4] == 'x') | |
2915 | i960_last_insn_type = I_TYPE_MEM; | |
2916 | else | |
2917 | i960_last_insn_type = I_TYPE_CTRL; | |
2918 | } | |
2919 | else if (p[1] == 'm') | |
2920 | { | |
2921 | if (p[3] == 'd') | |
2922 | i960_last_insn_type = I_TYPE_REG; | |
2923 | else if (p[4] == 'b' || p[4] == 'j') | |
2924 | i960_last_insn_type = I_TYPE_CTRL; | |
2925 | else | |
2926 | i960_last_insn_type = I_TYPE_REG; | |
2927 | } | |
2928 | else | |
2929 | i960_last_insn_type = I_TYPE_REG; | |
2930 | break; | |
2931 | ||
2932 | case 'l': | |
2933 | i960_last_insn_type = I_TYPE_MEM; | |
2934 | break; | |
2935 | ||
2936 | case 's': | |
2937 | if (p[1] == 't') | |
2938 | i960_last_insn_type = I_TYPE_MEM; | |
2939 | else | |
2940 | i960_last_insn_type = I_TYPE_REG; | |
2941 | break; | |
2942 | } | |
2943 | } |