]>
Commit | Line | Data |
---|---|---|
9878760c | 1 | /* Subroutines used for code generation on IBM RS/6000. |
fab3bcc3 RK |
2 | Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc. |
3 | Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu) | |
9878760c RK |
4 | |
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | #include <stdio.h> | |
22 | #include "config.h" | |
23 | #include "rtl.h" | |
24 | #include "regs.h" | |
25 | #include "hard-reg-set.h" | |
26 | #include "real.h" | |
27 | #include "insn-config.h" | |
28 | #include "conditions.h" | |
29 | #include "insn-flags.h" | |
30 | #include "output.h" | |
31 | #include "insn-attr.h" | |
32 | #include "flags.h" | |
33 | #include "recog.h" | |
34 | #include "expr.h" | |
35 | #include "obstack.h" | |
9b30bae2 JW |
36 | #include "tree.h" |
37 | ||
38 | extern char *language_string; | |
5248c961 | 39 | extern int profile_block_flag; |
9878760c RK |
40 | |
41 | #define min(A,B) ((A) < (B) ? (A) : (B)) | |
42 | #define max(A,B) ((A) > (B) ? (A) : (B)) | |
43 | ||
5248c961 RK |
44 | /* Target cpu type */ |
45 | ||
46 | enum processor_type rs6000_cpu; | |
47 | char *rs6000_cpu_string; | |
48 | ||
9878760c RK |
49 | /* Set to non-zero by "fix" operation to indicate that itrunc and |
50 | uitrunc must be defined. */ | |
51 | ||
52 | int rs6000_trunc_used; | |
53 | ||
54 | /* Set to non-zero once they have been defined. */ | |
55 | ||
56 | static int trunc_defined; | |
57 | ||
c764f757 RK |
58 | /* Set to non-zero once AIX common-mode calls have been defined. */ |
59 | static int common_mode_defined; | |
9878760c RK |
60 | /* Save information from a "cmpxx" operation until the branch or scc is |
61 | emitted. */ | |
62 | ||
63 | rtx rs6000_compare_op0, rs6000_compare_op1; | |
64 | int rs6000_compare_fp_p; | |
65 | \f | |
5248c961 RK |
66 | /* Override command line options. Mostly we process the processor |
67 | type and sometimes adjust other TARGET_ options. */ | |
68 | ||
69 | void | |
70 | rs6000_override_options () | |
71 | { | |
72 | int i; | |
73 | ||
85638c0d RK |
74 | /* Simplify the entries below by making a mask for any POWER |
75 | variant and any PowerPC variant. */ | |
76 | ||
77 | #define POWER_MASKS (MASK_POWER | MASK_POWER2) | |
fab3bcc3 | 78 | #define POWERPC_MASKS (MASK_POWERPC | MASK_PPCFPX | MASK_POWERPC64) |
85638c0d | 79 | |
5248c961 RK |
80 | static struct ptt |
81 | { | |
82 | char *name; /* Canonical processor name. */ | |
83 | enum processor_type processor; /* Processor type enum value. */ | |
84 | int target_enable; /* Target flags to enable. */ | |
85 | int target_disable; /* Target flags to disable. */ | |
86 | } processor_target_table[] | |
85638c0d RK |
87 | = {{"all", PROCESSOR_DEFAULT, 0, POWER_MASKS | POWERPC_MASKS}, |
88 | {"rios", PROCESSOR_RIOS1, MASK_POWER, MASK_POWER2 | POWERPC_MASKS}, | |
89 | {"rios1", PROCESSOR_RIOS1, MASK_POWER, MASK_POWER2 | POWERPC_MASKS}, | |
33898315 RK |
90 | {"rsc", PROCESSOR_PPC601, MASK_POWER, MASK_POWER2 | POWERPC_MASKS}, |
91 | {"rsc1", PROCESSOR_PPC601, MASK_POWER, MASK_POWER2 | POWERPC_MASKS}, | |
85638c0d | 92 | {"rios2", PROCESSOR_RIOS2, MASK_POWER | MASK_POWER2 , POWERPC_MASKS}, |
5248c961 | 93 | {"601", PROCESSOR_PPC601, |
85638c0d | 94 | MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS, |
fab3bcc3 | 95 | MASK_POWER2 | MASK_PPCFPX | MASK_POWERPC64}, |
49947f18 | 96 | {"mpc601", PROCESSOR_PPC601, |
85638c0d | 97 | MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS, |
fab3bcc3 | 98 | MASK_POWER2 | MASK_PPCFPX | MASK_POWERPC64}, |
85638c0d RK |
99 | {"ppc601", PROCESSOR_PPC601, |
100 | MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
fab3bcc3 | 101 | MASK_POWER2 | MASK_PPCFPX | MASK_POWERPC64}, |
5248c961 | 102 | {"603", PROCESSOR_PPC603, |
fab3bcc3 | 103 | MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS, |
85638c0d | 104 | POWER_MASKS | MASK_POWERPC64}, |
49947f18 | 105 | {"mpc603", PROCESSOR_PPC603, |
fab3bcc3 | 106 | MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS, |
85638c0d RK |
107 | POWER_MASKS | MASK_POWERPC64}, |
108 | {"ppc603", PROCESSOR_PPC603, | |
fab3bcc3 | 109 | MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS, |
85638c0d | 110 | POWER_MASKS | MASK_POWERPC64}, |
5248c961 | 111 | {"604", PROCESSOR_PPC604, |
fab3bcc3 | 112 | MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS, |
85638c0d | 113 | POWER_MASKS | MASK_POWERPC64}, |
49947f18 | 114 | {"mpc604", PROCESSOR_PPC604, |
fab3bcc3 | 115 | MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS, |
85638c0d RK |
116 | POWER_MASKS | MASK_POWERPC64}, |
117 | {"ppc604", PROCESSOR_PPC604, | |
fab3bcc3 | 118 | MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS, |
85638c0d | 119 | POWER_MASKS | MASK_POWERPC64}, |
5248c961 | 120 | {"620", PROCESSOR_PPC620, |
fab3bcc3 | 121 | (MASK_POWERPC | MASK_PPCFPX | MASK_POWERPC64 |
85638c0d RK |
122 | | MASK_NEW_MNEMONICS), |
123 | POWER_MASKS}, | |
49947f18 | 124 | {"mpc620", PROCESSOR_PPC620, |
fab3bcc3 | 125 | (MASK_POWERPC | MASK_PPCFPX | MASK_POWERPC64 |
85638c0d RK |
126 | | MASK_NEW_MNEMONICS), |
127 | POWER_MASKS}, | |
128 | {"ppc620", PROCESSOR_PPC620, | |
fab3bcc3 | 129 | (MASK_POWERPC | MASK_PPCFPX | MASK_POWERPC64 |
85638c0d RK |
130 | | MASK_NEW_MNEMONICS), |
131 | POWER_MASKS}}; | |
5248c961 RK |
132 | |
133 | int ptt_size = sizeof (processor_target_table) / sizeof (struct ptt); | |
134 | ||
135 | profile_block_flag = 0; | |
136 | ||
137 | /* Identify the processor type */ | |
138 | if (rs6000_cpu_string == 0) | |
139 | rs6000_cpu = PROCESSOR_DEFAULT; | |
140 | else | |
141 | { | |
142 | for (i = 0; i < ptt_size; i++) | |
143 | if (! strcmp (rs6000_cpu_string, processor_target_table[i].name)) | |
144 | { | |
145 | rs6000_cpu = processor_target_table[i].processor; | |
146 | target_flags |= processor_target_table[i].target_enable; | |
147 | target_flags &= ~processor_target_table[i].target_disable; | |
148 | break; | |
149 | } | |
150 | ||
151 | if (i == ptt_size) | |
152 | { | |
153 | error ("bad value (%s) for -mcpu= switch", rs6000_cpu_string); | |
154 | rs6000_cpu_string = "default"; | |
155 | rs6000_cpu = PROCESSOR_DEFAULT; | |
156 | } | |
157 | } | |
158 | } | |
159 | \f | |
9878760c RK |
160 | /* Return non-zero if this function is known to have a null epilogue. */ |
161 | ||
162 | int | |
163 | direct_return () | |
164 | { | |
165 | return (reload_completed | |
166 | && first_reg_to_save () == 32 | |
167 | && first_fp_reg_to_save () == 64 | |
168 | && ! regs_ever_live[65] | |
169 | && ! rs6000_pushes_stack ()); | |
170 | } | |
171 | ||
172 | /* Returns 1 always. */ | |
173 | ||
174 | int | |
175 | any_operand (op, mode) | |
176 | register rtx op; | |
177 | enum machine_mode mode; | |
178 | { | |
179 | return 1; | |
180 | } | |
181 | ||
182 | /* Return 1 if OP is a constant that can fit in a D field. */ | |
183 | ||
184 | int | |
185 | short_cint_operand (op, mode) | |
186 | register rtx op; | |
187 | enum machine_mode mode; | |
188 | { | |
189 | return (GET_CODE (op) == CONST_INT | |
190 | && (unsigned) (INTVAL (op) + 0x8000) < 0x10000); | |
191 | } | |
192 | ||
193 | /* Similar for a unsigned D field. */ | |
194 | ||
195 | int | |
196 | u_short_cint_operand (op, mode) | |
197 | register rtx op; | |
198 | enum machine_mode mode; | |
199 | { | |
200 | return (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff0000) == 0); | |
201 | } | |
202 | ||
dcfedcd0 RK |
203 | /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */ |
204 | ||
205 | int | |
206 | non_short_cint_operand (op, mode) | |
207 | register rtx op; | |
208 | enum machine_mode mode; | |
209 | { | |
210 | return (GET_CODE (op) == CONST_INT | |
211 | && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000); | |
212 | } | |
213 | ||
9878760c RK |
214 | /* Returns 1 if OP is a register that is not special (i.e., not MQ, |
215 | ctr, or lr). */ | |
216 | ||
217 | int | |
cd2b37d9 | 218 | gpc_reg_operand (op, mode) |
9878760c RK |
219 | register rtx op; |
220 | enum machine_mode mode; | |
221 | { | |
222 | return (register_operand (op, mode) | |
223 | && (GET_CODE (op) != REG || REGNO (op) >= 67 || REGNO (op) < 64)); | |
224 | } | |
225 | ||
226 | /* Returns 1 if OP is either a pseudo-register or a register denoting a | |
227 | CR field. */ | |
228 | ||
229 | int | |
230 | cc_reg_operand (op, mode) | |
231 | register rtx op; | |
232 | enum machine_mode mode; | |
233 | { | |
234 | return (register_operand (op, mode) | |
235 | && (GET_CODE (op) != REG | |
236 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
237 | || CR_REGNO_P (REGNO (op)))); | |
238 | } | |
239 | ||
240 | /* Returns 1 if OP is either a constant integer valid for a D-field or a | |
241 | non-special register. If a register, it must be in the proper mode unless | |
242 | MODE is VOIDmode. */ | |
243 | ||
244 | int | |
245 | reg_or_short_operand (op, mode) | |
246 | register rtx op; | |
247 | enum machine_mode mode; | |
248 | { | |
f5a28898 | 249 | return short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
250 | } |
251 | ||
252 | /* Similar, except check if the negation of the constant would be valid for | |
253 | a D-field. */ | |
254 | ||
255 | int | |
256 | reg_or_neg_short_operand (op, mode) | |
257 | register rtx op; | |
258 | enum machine_mode mode; | |
259 | { | |
260 | if (GET_CODE (op) == CONST_INT) | |
261 | return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P'); | |
262 | ||
cd2b37d9 | 263 | return gpc_reg_operand (op, mode); |
9878760c RK |
264 | } |
265 | ||
266 | /* Return 1 if the operand is either a register or an integer whose high-order | |
267 | 16 bits are zero. */ | |
268 | ||
269 | int | |
270 | reg_or_u_short_operand (op, mode) | |
271 | register rtx op; | |
272 | enum machine_mode mode; | |
273 | { | |
274 | if (GET_CODE (op) == CONST_INT | |
275 | && (INTVAL (op) & 0xffff0000) == 0) | |
276 | return 1; | |
277 | ||
cd2b37d9 | 278 | return gpc_reg_operand (op, mode); |
9878760c RK |
279 | } |
280 | ||
281 | /* Return 1 is the operand is either a non-special register or ANY | |
282 | constant integer. */ | |
283 | ||
284 | int | |
285 | reg_or_cint_operand (op, mode) | |
286 | register rtx op; | |
287 | enum machine_mode mode; | |
288 | { | |
cd2b37d9 | 289 | return GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode); |
9878760c RK |
290 | } |
291 | ||
6f2f8311 RK |
292 | /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register |
293 | with one instruction per word. We only do this if we can safely read | |
294 | CONST_DOUBLE_{LOW,HIGH}. */ | |
9878760c RK |
295 | |
296 | int | |
297 | easy_fp_constant (op, mode) | |
298 | register rtx op; | |
299 | register enum machine_mode mode; | |
300 | { | |
301 | rtx low, high; | |
302 | ||
303 | if (GET_CODE (op) != CONST_DOUBLE | |
304 | || GET_MODE (op) != mode | |
305 | || GET_MODE_CLASS (mode) != MODE_FLOAT) | |
306 | return 0; | |
307 | ||
308 | high = operand_subword (op, 0, 0, mode); | |
309 | low = operand_subword (op, 1, 0, mode); | |
310 | ||
6f2f8311 | 311 | if (high == 0 || ! input_operand (high, word_mode)) |
9878760c RK |
312 | return 0; |
313 | ||
314 | return (mode == SFmode | |
6f2f8311 | 315 | || (low != 0 && input_operand (low, word_mode))); |
9878760c RK |
316 | } |
317 | ||
318 | /* Return 1 if the operand is either a floating-point register, a pseudo | |
319 | register, or memory. */ | |
320 | ||
321 | int | |
322 | fp_reg_or_mem_operand (op, mode) | |
323 | register rtx op; | |
324 | enum machine_mode mode; | |
325 | { | |
326 | return (memory_operand (op, mode) | |
327 | || (register_operand (op, mode) | |
328 | && (GET_CODE (op) != REG | |
329 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
330 | || FP_REGNO_P (REGNO (op))))); | |
331 | } | |
332 | ||
333 | /* Return 1 if the operand is either an easy FP constant (see above) or | |
334 | memory. */ | |
335 | ||
336 | int | |
337 | mem_or_easy_const_operand (op, mode) | |
338 | register rtx op; | |
339 | enum machine_mode mode; | |
340 | { | |
341 | return memory_operand (op, mode) || easy_fp_constant (op, mode); | |
342 | } | |
343 | ||
344 | /* Return 1 if the operand is either a non-special register or an item | |
345 | that can be used as the operand of an SI add insn. */ | |
346 | ||
347 | int | |
348 | add_operand (op, mode) | |
349 | register rtx op; | |
350 | enum machine_mode mode; | |
351 | { | |
352 | return (reg_or_short_operand (op, mode) | |
353 | || (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff) == 0)); | |
354 | } | |
355 | ||
dcfedcd0 RK |
356 | /* Return 1 if OP is a constant but not a valid add_operand. */ |
357 | ||
358 | int | |
359 | non_add_cint_operand (op, mode) | |
360 | register rtx op; | |
361 | enum machine_mode mode; | |
362 | { | |
363 | return (GET_CODE (op) == CONST_INT | |
364 | && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000 | |
365 | && (INTVAL (op) & 0xffff) != 0); | |
366 | } | |
367 | ||
9878760c RK |
368 | /* Return 1 if the operand is a non-special register or a constant that |
369 | can be used as the operand of an OR or XOR insn on the RS/6000. */ | |
370 | ||
371 | int | |
372 | logical_operand (op, mode) | |
373 | register rtx op; | |
374 | enum machine_mode mode; | |
375 | { | |
cd2b37d9 | 376 | return (gpc_reg_operand (op, mode) |
9878760c RK |
377 | || (GET_CODE (op) == CONST_INT |
378 | && ((INTVAL (op) & 0xffff0000) == 0 | |
379 | || (INTVAL (op) & 0xffff) == 0))); | |
380 | } | |
381 | ||
dcfedcd0 RK |
382 | /* Return 1 if C is a constant that is not a logical operand (as |
383 | above). */ | |
384 | ||
385 | int | |
386 | non_logical_cint_operand (op, mode) | |
387 | register rtx op; | |
388 | enum machine_mode mode; | |
389 | { | |
390 | return (GET_CODE (op) == CONST_INT | |
391 | && (INTVAL (op) & 0xffff0000) != 0 | |
392 | && (INTVAL (op) & 0xffff) != 0); | |
393 | } | |
394 | ||
9878760c RK |
395 | /* Return 1 if C is a constant that can be encoded in a mask on the |
396 | RS/6000. It is if there are no more than two 1->0 or 0->1 transitions. | |
397 | Reject all ones and all zeros, since these should have been optimized | |
398 | away and confuse the making of MB and ME. */ | |
399 | ||
400 | int | |
401 | mask_constant (c) | |
402 | register int c; | |
403 | { | |
404 | int i; | |
405 | int last_bit_value; | |
406 | int transitions = 0; | |
407 | ||
408 | if (c == 0 || c == ~0) | |
409 | return 0; | |
410 | ||
411 | last_bit_value = c & 1; | |
412 | ||
413 | for (i = 1; i < 32; i++) | |
414 | if (((c >>= 1) & 1) != last_bit_value) | |
415 | last_bit_value ^= 1, transitions++; | |
416 | ||
417 | return transitions <= 2; | |
418 | } | |
419 | ||
420 | /* Return 1 if the operand is a constant that is a mask on the RS/6000. */ | |
421 | ||
422 | int | |
423 | mask_operand (op, mode) | |
424 | register rtx op; | |
425 | enum machine_mode mode; | |
426 | { | |
427 | return GET_CODE (op) == CONST_INT && mask_constant (INTVAL (op)); | |
428 | } | |
429 | ||
430 | /* Return 1 if the operand is either a non-special register or a | |
431 | constant that can be used as the operand of an RS/6000 logical AND insn. */ | |
432 | ||
433 | int | |
434 | and_operand (op, mode) | |
435 | register rtx op; | |
436 | enum machine_mode mode; | |
437 | { | |
438 | return (reg_or_short_operand (op, mode) | |
439 | || logical_operand (op, mode) | |
440 | || mask_operand (op, mode)); | |
441 | } | |
442 | ||
dcfedcd0 RK |
443 | /* Return 1 if the operand is a constant but not a valid operand for an AND |
444 | insn. */ | |
445 | ||
446 | int | |
447 | non_and_cint_operand (op, mode) | |
448 | register rtx op; | |
449 | enum machine_mode mode; | |
450 | { | |
451 | return GET_CODE (op) == CONST_INT && ! and_operand (op, mode); | |
452 | } | |
453 | ||
9878760c RK |
454 | /* Return 1 if the operand is a general register or memory operand. */ |
455 | ||
456 | int | |
457 | reg_or_mem_operand (op, mode) | |
458 | register rtx op; | |
459 | register enum machine_mode mode; | |
460 | { | |
cd2b37d9 | 461 | return gpc_reg_operand (op, mode) || memory_operand (op, mode); |
9878760c RK |
462 | } |
463 | ||
464 | /* Return 1 if the operand, used inside a MEM, is a valid first argument | |
465 | to CALL. This is a SYMBOL_REF or a pseudo-register, which will be | |
466 | forced to lr. */ | |
467 | ||
468 | int | |
469 | call_operand (op, mode) | |
470 | register rtx op; | |
471 | enum machine_mode mode; | |
472 | { | |
473 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
474 | return 0; | |
475 | ||
476 | return (GET_CODE (op) == SYMBOL_REF | |
477 | || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER)); | |
478 | } | |
479 | ||
2af3d377 RK |
480 | |
481 | /* Return 1 if the operand is a SYMBOL_REF for a function known to be in | |
482 | this file. */ | |
483 | ||
484 | int | |
485 | current_file_function_operand (op, mode) | |
486 | register rtx op; | |
487 | enum machine_mode mode; | |
488 | { | |
489 | return (GET_CODE (op) == SYMBOL_REF | |
490 | && (SYMBOL_REF_FLAG (op) | |
491 | || op == XEXP (DECL_RTL (current_function_decl), 0))); | |
492 | } | |
493 | ||
494 | ||
9878760c RK |
495 | /* Return 1 if this operand is a valid input for a move insn. */ |
496 | ||
497 | int | |
498 | input_operand (op, mode) | |
499 | register rtx op; | |
500 | enum machine_mode mode; | |
501 | { | |
eb4e8003 | 502 | /* Memory is always valid. */ |
9878760c RK |
503 | if (memory_operand (op, mode)) |
504 | return 1; | |
505 | ||
eb4e8003 RK |
506 | /* For floating-point, easy constants are valid. */ |
507 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
508 | && CONSTANT_P (op) | |
509 | && easy_fp_constant (op, mode)) | |
510 | return 1; | |
511 | ||
512 | /* For floating-point or multi-word mode, the only remaining valid type | |
513 | is a register. */ | |
9878760c RK |
514 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
515 | || GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
eb4e8003 | 516 | return register_operand (op, mode); |
9878760c | 517 | |
88fe15a1 RK |
518 | /* The only cases left are integral modes one word or smaller (we |
519 | do not get called for MODE_CC values). These can be in any | |
520 | register. */ | |
521 | if (register_operand (op, mode)) | |
a8b3aeda | 522 | return 1; |
88fe15a1 RK |
523 | |
524 | /* For HImode and QImode, any constant is valid. */ | |
525 | if ((mode == HImode || mode == QImode) | |
526 | && GET_CODE (op) == CONST_INT) | |
9878760c RK |
527 | return 1; |
528 | ||
9878760c RK |
529 | /* Otherwise, we will be doing this SET with an add, so anything valid |
530 | for an add will be valid. */ | |
531 | return add_operand (op, mode); | |
532 | } | |
533 | \f | |
534 | /* Return 1 if OP is a load multiple operation. It is known to be a | |
535 | PARALLEL and the first section will be tested. */ | |
536 | ||
537 | int | |
538 | load_multiple_operation (op, mode) | |
539 | rtx op; | |
540 | enum machine_mode mode; | |
541 | { | |
542 | int count = XVECLEN (op, 0); | |
543 | int dest_regno; | |
544 | rtx src_addr; | |
545 | int i; | |
546 | ||
547 | /* Perform a quick check so we don't blow up below. */ | |
548 | if (count <= 1 | |
549 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
550 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
551 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
552 | return 0; | |
553 | ||
554 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
555 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
556 | ||
557 | for (i = 1; i < count; i++) | |
558 | { | |
559 | rtx elt = XVECEXP (op, 0, i); | |
560 | ||
561 | if (GET_CODE (elt) != SET | |
562 | || GET_CODE (SET_DEST (elt)) != REG | |
563 | || GET_MODE (SET_DEST (elt)) != SImode | |
564 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
565 | || GET_CODE (SET_SRC (elt)) != MEM | |
566 | || GET_MODE (SET_SRC (elt)) != SImode | |
567 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS | |
568 | || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr) | |
569 | || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT | |
570 | || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4) | |
571 | return 0; | |
572 | } | |
573 | ||
574 | return 1; | |
575 | } | |
576 | ||
577 | /* Similar, but tests for store multiple. Here, the second vector element | |
578 | is a CLOBBER. It will be tested later. */ | |
579 | ||
580 | int | |
581 | store_multiple_operation (op, mode) | |
582 | rtx op; | |
583 | enum machine_mode mode; | |
584 | { | |
585 | int count = XVECLEN (op, 0) - 1; | |
586 | int src_regno; | |
587 | rtx dest_addr; | |
588 | int i; | |
589 | ||
590 | /* Perform a quick check so we don't blow up below. */ | |
591 | if (count <= 1 | |
592 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
593 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
594 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
595 | return 0; | |
596 | ||
597 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
598 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
599 | ||
600 | for (i = 1; i < count; i++) | |
601 | { | |
602 | rtx elt = XVECEXP (op, 0, i + 1); | |
603 | ||
604 | if (GET_CODE (elt) != SET | |
605 | || GET_CODE (SET_SRC (elt)) != REG | |
606 | || GET_MODE (SET_SRC (elt)) != SImode | |
607 | || REGNO (SET_SRC (elt)) != src_regno + i | |
608 | || GET_CODE (SET_DEST (elt)) != MEM | |
609 | || GET_MODE (SET_DEST (elt)) != SImode | |
610 | || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS | |
611 | || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr) | |
612 | || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT | |
613 | || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4) | |
614 | return 0; | |
615 | } | |
616 | ||
617 | return 1; | |
618 | } | |
619 | \f | |
620 | /* Return 1 if OP is a comparison operation that is valid for a branch insn. | |
621 | We only check the opcode against the mode of the CC value here. */ | |
622 | ||
623 | int | |
624 | branch_comparison_operator (op, mode) | |
625 | register rtx op; | |
626 | enum machine_mode mode; | |
627 | { | |
628 | enum rtx_code code = GET_CODE (op); | |
629 | enum machine_mode cc_mode; | |
630 | ||
631 | if (GET_RTX_CLASS (code) != '<') | |
632 | return 0; | |
633 | ||
634 | cc_mode = GET_MODE (XEXP (op, 0)); | |
635 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
636 | return 0; | |
637 | ||
638 | if ((code == GT || code == LT || code == GE || code == LE) | |
639 | && cc_mode == CCUNSmode) | |
640 | return 0; | |
641 | ||
642 | if ((code == GTU || code == LTU || code == GEU || code == LEU) | |
643 | && (cc_mode != CCUNSmode)) | |
644 | return 0; | |
645 | ||
646 | return 1; | |
647 | } | |
648 | ||
649 | /* Return 1 if OP is a comparison operation that is valid for an scc insn. | |
650 | We check the opcode against the mode of the CC value and disallow EQ or | |
651 | NE comparisons for integers. */ | |
652 | ||
653 | int | |
654 | scc_comparison_operator (op, mode) | |
655 | register rtx op; | |
656 | enum machine_mode mode; | |
657 | { | |
658 | enum rtx_code code = GET_CODE (op); | |
659 | enum machine_mode cc_mode; | |
660 | ||
661 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
662 | return 0; | |
663 | ||
664 | if (GET_RTX_CLASS (code) != '<') | |
665 | return 0; | |
666 | ||
667 | cc_mode = GET_MODE (XEXP (op, 0)); | |
668 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
669 | return 0; | |
670 | ||
671 | if (code == NE && cc_mode != CCFPmode) | |
672 | return 0; | |
673 | ||
674 | if ((code == GT || code == LT || code == GE || code == LE) | |
675 | && cc_mode == CCUNSmode) | |
676 | return 0; | |
677 | ||
678 | if ((code == GTU || code == LTU || code == GEU || code == LEU) | |
679 | && (cc_mode != CCUNSmode)) | |
680 | return 0; | |
681 | ||
c5defebb RK |
682 | if (cc_mode == CCEQmode && code != EQ && code != NE) |
683 | return 0; | |
684 | ||
9878760c RK |
685 | return 1; |
686 | } | |
687 | \f | |
688 | /* Return 1 if ANDOP is a mask that has no bits on that are not in the | |
689 | mask required to convert the result of a rotate insn into a shift | |
690 | left insn of SHIFTOP bits. Both are known to be CONST_INT. */ | |
691 | ||
692 | int | |
693 | includes_lshift_p (shiftop, andop) | |
694 | register rtx shiftop; | |
695 | register rtx andop; | |
696 | { | |
697 | int shift_mask = (~0 << INTVAL (shiftop)); | |
698 | ||
699 | return (INTVAL (andop) & ~shift_mask) == 0; | |
700 | } | |
701 | ||
702 | /* Similar, but for right shift. */ | |
703 | ||
704 | int | |
705 | includes_rshift_p (shiftop, andop) | |
706 | register rtx shiftop; | |
707 | register rtx andop; | |
708 | { | |
709 | unsigned shift_mask = ~0; | |
710 | ||
711 | shift_mask >>= INTVAL (shiftop); | |
712 | ||
713 | return (INTVAL (andop) & ~ shift_mask) == 0; | |
714 | } | |
715 | \f | |
716 | /* Return the register class of a scratch register needed to copy IN into | |
717 | or out of a register in CLASS in MODE. If it can be done directly, | |
718 | NO_REGS is returned. */ | |
719 | ||
720 | enum reg_class | |
721 | secondary_reload_class (class, mode, in) | |
722 | enum reg_class class; | |
723 | enum machine_mode mode; | |
724 | rtx in; | |
725 | { | |
726 | int regno = true_regnum (in); | |
727 | ||
728 | if (regno >= FIRST_PSEUDO_REGISTER) | |
729 | regno = -1; | |
730 | ||
731 | /* We can place anything into GENERAL_REGS and can put GENERAL_REGS | |
732 | into anything. */ | |
733 | if (class == GENERAL_REGS || class == BASE_REGS | |
734 | || (regno >= 0 && INT_REGNO_P (regno))) | |
735 | return NO_REGS; | |
736 | ||
737 | /* Constants, memory, and FP registers can go into FP registers. */ | |
738 | if ((regno == -1 || FP_REGNO_P (regno)) | |
739 | && (class == FLOAT_REGS || class == NON_SPECIAL_REGS)) | |
740 | return NO_REGS; | |
741 | ||
742 | /* We can copy among the CR registers. */ | |
743 | if ((class == CR_REGS || class == CR0_REGS) | |
744 | && regno >= 0 && CR_REGNO_P (regno)) | |
745 | return NO_REGS; | |
746 | ||
747 | /* Otherwise, we need GENERAL_REGS. */ | |
748 | return GENERAL_REGS; | |
749 | } | |
750 | \f | |
751 | /* Given a comparison operation, return the bit number in CCR to test. We | |
752 | know this is a valid comparison. | |
753 | ||
754 | SCC_P is 1 if this is for an scc. That means that %D will have been | |
755 | used instead of %C, so the bits will be in different places. | |
756 | ||
b4ac57ab | 757 | Return -1 if OP isn't a valid comparison for some reason. */ |
9878760c RK |
758 | |
759 | int | |
760 | ccr_bit (op, scc_p) | |
761 | register rtx op; | |
762 | int scc_p; | |
763 | { | |
764 | enum rtx_code code = GET_CODE (op); | |
765 | enum machine_mode cc_mode; | |
766 | int cc_regnum; | |
767 | int base_bit; | |
768 | ||
769 | if (GET_RTX_CLASS (code) != '<') | |
770 | return -1; | |
771 | ||
772 | cc_mode = GET_MODE (XEXP (op, 0)); | |
773 | cc_regnum = REGNO (XEXP (op, 0)); | |
774 | base_bit = 4 * (cc_regnum - 68); | |
775 | ||
c5defebb RK |
776 | /* In CCEQmode cases we have made sure that the result is always in the |
777 | third bit of the CR field. */ | |
778 | ||
779 | if (cc_mode == CCEQmode) | |
780 | return base_bit + 3; | |
781 | ||
9878760c RK |
782 | switch (code) |
783 | { | |
784 | case NE: | |
785 | return scc_p ? base_bit + 3 : base_bit + 2; | |
786 | case EQ: | |
787 | return base_bit + 2; | |
788 | case GT: case GTU: | |
789 | return base_bit + 1; | |
790 | case LT: case LTU: | |
791 | return base_bit; | |
792 | ||
793 | case GE: case GEU: | |
794 | /* If floating-point, we will have done a cror to put the bit in the | |
795 | unordered position. So test that bit. For integer, this is ! LT | |
796 | unless this is an scc insn. */ | |
797 | return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit; | |
798 | ||
799 | case LE: case LEU: | |
800 | return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1; | |
801 | ||
802 | default: | |
803 | abort (); | |
804 | } | |
805 | } | |
806 | \f | |
807 | /* Print an operand. Recognize special options, documented below. */ | |
808 | ||
809 | void | |
810 | print_operand (file, x, code) | |
811 | FILE *file; | |
812 | rtx x; | |
813 | char code; | |
814 | { | |
815 | int i; | |
816 | int val; | |
817 | ||
818 | /* These macros test for integers and extract the low-order bits. */ | |
819 | #define INT_P(X) \ | |
820 | ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \ | |
821 | && GET_MODE (X) == VOIDmode) | |
822 | ||
823 | #define INT_LOWPART(X) \ | |
824 | (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X)) | |
825 | ||
826 | switch (code) | |
827 | { | |
a8b3aeda | 828 | case '.': |
a85d226b RK |
829 | /* Write out an instruction after the call which may be replaced |
830 | with glue code by the loader. This depends on the AIX version. */ | |
831 | asm_fprintf (file, RS6000_CALL_GLUE); | |
a8b3aeda RK |
832 | return; |
833 | ||
9854d9ed RK |
834 | case 'A': |
835 | /* If X is a constant integer whose low-order 5 bits are zero, | |
836 | write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug | |
76229ac8 | 837 | in the AIX assembler where "sri" with a zero shift count |
9854d9ed RK |
838 | write a trash instruction. */ |
839 | if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0) | |
76229ac8 | 840 | putc ('l', file); |
9854d9ed | 841 | else |
76229ac8 | 842 | putc ('r', file); |
9854d9ed RK |
843 | return; |
844 | ||
845 | case 'b': | |
846 | /* Low-order 16 bits of constant, unsigned. */ | |
cad12a8d | 847 | if (! INT_P (x)) |
9854d9ed | 848 | output_operand_lossage ("invalid %%b value"); |
cad12a8d | 849 | |
9854d9ed | 850 | fprintf (file, "%d", INT_LOWPART (x) & 0xffff); |
cad12a8d RK |
851 | return; |
852 | ||
9854d9ed RK |
853 | case 'C': |
854 | /* This is an optional cror needed for LE or GE floating-point | |
855 | comparisons. Otherwise write nothing. */ | |
856 | if ((GET_CODE (x) == LE || GET_CODE (x) == GE) | |
857 | && GET_MODE (XEXP (x, 0)) == CCFPmode) | |
858 | { | |
859 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68); | |
860 | ||
861 | fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3, | |
862 | base_bit + 2, base_bit + (GET_CODE (x) == GE)); | |
863 | } | |
864 | return; | |
865 | ||
866 | case 'D': | |
867 | /* Similar, except that this is for an scc, so we must be able to | |
868 | encode the test in a single bit that is one. We do the above | |
869 | for any LE, GE, GEU, or LEU and invert the bit for NE. */ | |
870 | if (GET_CODE (x) == LE || GET_CODE (x) == GE | |
871 | || GET_CODE (x) == LEU || GET_CODE (x) == GEU) | |
872 | { | |
873 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68); | |
874 | ||
875 | fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3, | |
876 | base_bit + 2, | |
877 | base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU)); | |
878 | } | |
879 | ||
880 | else if (GET_CODE (x) == NE) | |
881 | { | |
882 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68); | |
883 | ||
884 | fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3, | |
885 | base_bit + 2, base_bit + 2); | |
886 | } | |
887 | return; | |
888 | ||
889 | case 'E': | |
890 | /* X is a CR register. Print the number of the third bit of the CR */ | |
891 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
892 | output_operand_lossage ("invalid %%E value"); | |
893 | ||
894 | fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3); | |
a85d226b | 895 | return; |
9854d9ed RK |
896 | |
897 | case 'f': | |
898 | /* X is a CR register. Print the shift count needed to move it | |
899 | to the high-order four bits. */ | |
900 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
901 | output_operand_lossage ("invalid %%f value"); | |
902 | else | |
903 | fprintf (file, "%d", 4 * (REGNO (x) - 68)); | |
904 | return; | |
905 | ||
906 | case 'F': | |
907 | /* Similar, but print the count for the rotate in the opposite | |
908 | direction. */ | |
909 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
910 | output_operand_lossage ("invalid %%F value"); | |
911 | else | |
912 | fprintf (file, "%d", 32 - 4 * (REGNO (x) - 68)); | |
913 | return; | |
914 | ||
915 | case 'G': | |
916 | /* X is a constant integer. If it is negative, print "m", | |
917 | otherwise print "z". This is to make a aze or ame insn. */ | |
918 | if (GET_CODE (x) != CONST_INT) | |
919 | output_operand_lossage ("invalid %%G value"); | |
920 | else if (INTVAL (x) >= 0) | |
76229ac8 | 921 | putc ('z', file); |
9854d9ed | 922 | else |
76229ac8 | 923 | putc ('m', file); |
9854d9ed RK |
924 | return; |
925 | ||
9878760c | 926 | case 'h': |
df3d94ed RK |
927 | /* If constant, output low-order five bits. Otherwise, |
928 | write normally. */ | |
9878760c RK |
929 | if (INT_P (x)) |
930 | fprintf (file, "%d", INT_LOWPART (x) & 31); | |
931 | else | |
932 | print_operand (file, x, 0); | |
933 | return; | |
934 | ||
935 | case 'H': | |
df3d94ed | 936 | /* X must be a constant. Output the low order 5 bits plus 24. */ |
9878760c RK |
937 | if (! INT_P (x)) |
938 | output_operand_lossage ("invalid %%H value"); | |
939 | ||
940 | fprintf (file, "%d", (INT_LOWPART (x) + 24) & 31); | |
941 | return; | |
942 | ||
9854d9ed RK |
943 | case 'I': |
944 | /* Print `i' if this is a constant, else nothing. */ | |
9878760c | 945 | if (INT_P (x)) |
76229ac8 | 946 | putc ('i', file); |
9878760c RK |
947 | return; |
948 | ||
9854d9ed RK |
949 | case 'j': |
950 | /* Write the bit number in CCR for jump. */ | |
951 | i = ccr_bit (x, 0); | |
952 | if (i == -1) | |
953 | output_operand_lossage ("invalid %%j code"); | |
9878760c | 954 | else |
9854d9ed | 955 | fprintf (file, "%d", i); |
9878760c RK |
956 | return; |
957 | ||
9854d9ed RK |
958 | case 'J': |
959 | /* Similar, but add one for shift count in rlinm for scc and pass | |
960 | scc flag to `ccr_bit'. */ | |
961 | i = ccr_bit (x, 1); | |
962 | if (i == -1) | |
963 | output_operand_lossage ("invalid %%J code"); | |
964 | else | |
a0466a68 RK |
965 | /* If we want bit 31, write a shift count of zero, not 32. */ |
966 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9878760c RK |
967 | return; |
968 | ||
9854d9ed RK |
969 | case 'k': |
970 | /* X must be a constant. Write the 1's complement of the | |
971 | constant. */ | |
9878760c | 972 | if (! INT_P (x)) |
9854d9ed | 973 | output_operand_lossage ("invalid %%k value"); |
9878760c | 974 | |
9854d9ed | 975 | fprintf (file, "%d", ~ INT_LOWPART (x)); |
9878760c RK |
976 | return; |
977 | ||
9854d9ed RK |
978 | case 'L': |
979 | /* Write second word of DImode or DFmode reference. Works on register | |
980 | or non-indexed memory only. */ | |
981 | if (GET_CODE (x) == REG) | |
982 | fprintf (file, "%d", REGNO (x) + 1); | |
983 | else if (GET_CODE (x) == MEM) | |
984 | { | |
985 | /* Handle possible auto-increment. Since it is pre-increment and | |
986 | we have already done it, we can just use an offset of four. */ | |
987 | if (GET_CODE (XEXP (x, 0)) == PRE_INC | |
988 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
989 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4)); | |
990 | else | |
991 | output_address (plus_constant (XEXP (x, 0), 4)); | |
992 | } | |
9878760c | 993 | return; |
9854d9ed | 994 | |
9878760c RK |
995 | case 'm': |
996 | /* MB value for a mask operand. */ | |
997 | if (! mask_operand (x, VOIDmode)) | |
998 | output_operand_lossage ("invalid %%m value"); | |
999 | ||
1000 | val = INT_LOWPART (x); | |
1001 | ||
1002 | /* If the high bit is set and the low bit is not, the value is zero. | |
1003 | If the high bit is zero, the value is the first 1 bit we find from | |
1004 | the left. */ | |
1005 | if (val < 0 && (val & 1) == 0) | |
1006 | { | |
1007 | fprintf (file, "0"); | |
1008 | return; | |
1009 | } | |
1010 | else if (val >= 0) | |
1011 | { | |
1012 | for (i = 1; i < 32; i++) | |
1013 | if ((val <<= 1) < 0) | |
1014 | break; | |
1015 | fprintf (file, "%d", i); | |
1016 | return; | |
1017 | } | |
1018 | ||
1019 | /* Otherwise, look for the first 0 bit from the right. The result is its | |
1020 | number plus 1. We know the low-order bit is one. */ | |
1021 | for (i = 0; i < 32; i++) | |
1022 | if (((val >>= 1) & 1) == 0) | |
1023 | break; | |
1024 | ||
1025 | /* If we ended in ...01, I would be 0. The correct value is 31, so | |
1026 | we want 31 - i. */ | |
1027 | fprintf (file, "%d", 31 - i); | |
1028 | return; | |
1029 | ||
1030 | case 'M': | |
1031 | /* ME value for a mask operand. */ | |
1032 | if (! mask_operand (x, VOIDmode)) | |
1033 | output_operand_lossage ("invalid %%m value"); | |
1034 | ||
1035 | val = INT_LOWPART (x); | |
1036 | ||
1037 | /* If the low bit is set and the high bit is not, the value is 31. | |
1038 | If the low bit is zero, the value is the first 1 bit we find from | |
1039 | the right. */ | |
1040 | if ((val & 1) && val >= 0) | |
1041 | { | |
76229ac8 | 1042 | fputs ("31", file); |
9878760c RK |
1043 | return; |
1044 | } | |
1045 | else if ((val & 1) == 0) | |
1046 | { | |
1047 | for (i = 0; i < 32; i++) | |
1048 | if ((val >>= 1) & 1) | |
1049 | break; | |
1050 | ||
1051 | /* If we had ....10, I would be 0. The result should be | |
1052 | 30, so we need 30 - i. */ | |
1053 | fprintf (file, "%d", 30 - i); | |
1054 | return; | |
1055 | } | |
1056 | ||
1057 | /* Otherwise, look for the first 0 bit from the left. The result is its | |
1058 | number minus 1. We know the high-order bit is one. */ | |
1059 | for (i = 0; i < 32; i++) | |
1060 | if ((val <<= 1) >= 0) | |
1061 | break; | |
1062 | ||
1063 | fprintf (file, "%d", i); | |
1064 | return; | |
1065 | ||
9878760c RK |
1066 | case 'N': |
1067 | /* Write the number of elements in the vector times 4. */ | |
1068 | if (GET_CODE (x) != PARALLEL) | |
1069 | output_operand_lossage ("invalid %%N value"); | |
1070 | ||
1071 | fprintf (file, "%d", XVECLEN (x, 0) * 4); | |
1072 | return; | |
1073 | ||
1074 | case 'O': | |
1075 | /* Similar, but subtract 1 first. */ | |
1076 | if (GET_CODE (x) != PARALLEL) | |
1077 | output_operand_lossage ("invalid %%N value"); | |
1078 | ||
1079 | fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4); | |
1080 | return; | |
1081 | ||
9854d9ed RK |
1082 | case 'p': |
1083 | /* X is a CONST_INT that is a power of two. Output the logarithm. */ | |
1084 | if (! INT_P (x) | |
1085 | || (i = exact_log2 (INT_LOWPART (x))) < 0) | |
1086 | output_operand_lossage ("invalid %%p value"); | |
1087 | ||
1088 | fprintf (file, "%d", i); | |
1089 | return; | |
1090 | ||
9878760c RK |
1091 | case 'P': |
1092 | /* The operand must be an indirect memory reference. The result | |
1093 | is the register number. */ | |
1094 | if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG | |
1095 | || REGNO (XEXP (x, 0)) >= 32) | |
1096 | output_operand_lossage ("invalid %%P value"); | |
1097 | ||
1098 | fprintf (file, "%d", REGNO (XEXP (x, 0))); | |
1099 | return; | |
1100 | ||
9854d9ed RK |
1101 | case 'R': |
1102 | /* X is a CR register. Print the mask for `mtcrf'. */ | |
1103 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
1104 | output_operand_lossage ("invalid %%R value"); | |
1105 | else | |
1106 | fprintf (file, "%d", 128 >> (REGNO (x) - 68)); | |
9878760c | 1107 | return; |
9854d9ed RK |
1108 | |
1109 | case 's': | |
1110 | /* Low 5 bits of 32 - value */ | |
1111 | if (! INT_P (x)) | |
1112 | output_operand_lossage ("invalid %%s value"); | |
1113 | ||
1114 | fprintf (file, "%d", (32 - INT_LOWPART (x)) & 31); | |
9878760c | 1115 | return; |
9854d9ed RK |
1116 | |
1117 | case 'S': | |
1118 | /* Low 5 bits of 31 - value */ | |
1119 | if (! INT_P (x)) | |
1120 | output_operand_lossage ("invalid %%S value"); | |
1121 | ||
1122 | fprintf (file, "%d", (31 - INT_LOWPART (x)) & 31); | |
9878760c | 1123 | return; |
9854d9ed | 1124 | |
9878760c RK |
1125 | case 't': |
1126 | /* Write 12 if this jump operation will branch if true, 4 otherwise. | |
1127 | All floating-point operations except NE branch true and integer | |
1128 | EQ, LT, GT, LTU and GTU also branch true. */ | |
1129 | if (GET_RTX_CLASS (GET_CODE (x)) != '<') | |
1130 | output_operand_lossage ("invalid %%t value"); | |
1131 | ||
1132 | else if ((GET_MODE (XEXP (x, 0)) == CCFPmode | |
1133 | && GET_CODE (x) != NE) | |
1134 | || GET_CODE (x) == EQ | |
1135 | || GET_CODE (x) == LT || GET_CODE (x) == GT | |
1136 | || GET_CODE (x) == LTU || GET_CODE (x) == GTU) | |
76229ac8 | 1137 | fputs ("12", file); |
9878760c | 1138 | else |
76229ac8 | 1139 | putc ('4', file); |
9878760c RK |
1140 | return; |
1141 | ||
1142 | case 'T': | |
1143 | /* Opposite of 't': write 4 if this jump operation will branch if true, | |
1144 | 12 otherwise. */ | |
1145 | if (GET_RTX_CLASS (GET_CODE (x)) != '<') | |
1146 | output_operand_lossage ("invalid %%t value"); | |
1147 | ||
1148 | else if ((GET_MODE (XEXP (x, 0)) == CCFPmode | |
1149 | && GET_CODE (x) != NE) | |
1150 | || GET_CODE (x) == EQ | |
1151 | || GET_CODE (x) == LT || GET_CODE (x) == GT | |
1152 | || GET_CODE (x) == LTU || GET_CODE (x) == GTU) | |
76229ac8 | 1153 | putc ('4', file); |
9878760c | 1154 | else |
76229ac8 | 1155 | fputs ("12", file); |
9878760c RK |
1156 | return; |
1157 | ||
9854d9ed RK |
1158 | case 'u': |
1159 | /* High-order 16 bits of constant. */ | |
1160 | if (! INT_P (x)) | |
1161 | output_operand_lossage ("invalid %%u value"); | |
9878760c | 1162 | |
76229ac8 | 1163 | fprintf (file, "0x%x", (INT_LOWPART (x) >> 16) & 0xffff); |
9878760c RK |
1164 | return; |
1165 | ||
9854d9ed RK |
1166 | case 'U': |
1167 | /* Print `u' if this has an auto-increment or auto-decrement. */ | |
1168 | if (GET_CODE (x) == MEM | |
1169 | && (GET_CODE (XEXP (x, 0)) == PRE_INC | |
1170 | || GET_CODE (XEXP (x, 0)) == PRE_DEC)) | |
76229ac8 | 1171 | putc ('u', file); |
9854d9ed | 1172 | return; |
9878760c | 1173 | |
9854d9ed RK |
1174 | case 'w': |
1175 | /* If constant, low-order 16 bits of constant, signed. Otherwise, write | |
1176 | normally. */ | |
1177 | if (INT_P (x)) | |
1178 | fprintf (file, "%d", | |
1179 | (INT_LOWPART (x) & 0xffff) - 2 * (INT_LOWPART (x) & 0x8000)); | |
1180 | else | |
1181 | print_operand (file, x, 0); | |
9878760c RK |
1182 | return; |
1183 | ||
9854d9ed RK |
1184 | case 'W': |
1185 | /* If constant, low-order 16 bits of constant, unsigned. | |
1186 | Otherwise, write normally. */ | |
1187 | if (INT_P (x)) | |
1188 | fprintf (file, "%d", INT_LOWPART (x) & 0xffff); | |
1189 | else | |
1190 | print_operand (file, x, 0); | |
1191 | return; | |
9878760c | 1192 | |
9854d9ed RK |
1193 | case 'X': |
1194 | if (GET_CODE (x) == MEM | |
1195 | && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0))) | |
76229ac8 | 1196 | putc ('x', file); |
9854d9ed | 1197 | return; |
9878760c | 1198 | |
9854d9ed RK |
1199 | case 'Y': |
1200 | /* Like 'L', for third word of TImode */ | |
1201 | if (GET_CODE (x) == REG) | |
1202 | fprintf (file, "%d", REGNO (x) + 2); | |
1203 | else if (GET_CODE (x) == MEM) | |
9878760c | 1204 | { |
9854d9ed RK |
1205 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
1206 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
1207 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8)); | |
1208 | else | |
1209 | output_address (plus_constant (XEXP (x, 0), 8)); | |
9878760c RK |
1210 | } |
1211 | return; | |
9854d9ed | 1212 | |
9878760c | 1213 | case 'z': |
b4ac57ab RS |
1214 | /* X is a SYMBOL_REF. Write out the name preceded by a |
1215 | period and without any trailing data in brackets. Used for function | |
9878760c RK |
1216 | names. */ |
1217 | if (GET_CODE (x) != SYMBOL_REF) | |
1218 | abort (); | |
1219 | ||
76229ac8 | 1220 | putc ('.', file); |
9878760c RK |
1221 | RS6000_OUTPUT_BASENAME (file, XSTR (x, 0)); |
1222 | return; | |
1223 | ||
9854d9ed RK |
1224 | case 'Z': |
1225 | /* Like 'L', for last word of TImode. */ | |
1226 | if (GET_CODE (x) == REG) | |
1227 | fprintf (file, "%d", REGNO (x) + 3); | |
1228 | else if (GET_CODE (x) == MEM) | |
1229 | { | |
1230 | if (GET_CODE (XEXP (x, 0)) == PRE_INC | |
1231 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
1232 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12)); | |
1233 | else | |
1234 | output_address (plus_constant (XEXP (x, 0), 12)); | |
1235 | } | |
5c23c401 | 1236 | return; |
9854d9ed | 1237 | |
9878760c RK |
1238 | case 0: |
1239 | if (GET_CODE (x) == REG) | |
1240 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
1241 | else if (GET_CODE (x) == MEM) | |
1242 | { | |
1243 | /* We need to handle PRE_INC and PRE_DEC here, since we need to | |
1244 | know the width from the mode. */ | |
1245 | if (GET_CODE (XEXP (x, 0)) == PRE_INC) | |
1246 | fprintf (file, "%d(%d)", GET_MODE_SIZE (GET_MODE (x)), | |
1247 | REGNO (XEXP (XEXP (x, 0), 0))); | |
1248 | else if (GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
1249 | fprintf (file, "%d(%d)", - GET_MODE_SIZE (GET_MODE (x)), | |
1250 | REGNO (XEXP (XEXP (x, 0), 0))); | |
1251 | else | |
1252 | output_address (XEXP (x, 0)); | |
1253 | } | |
1254 | else | |
1255 | output_addr_const (file, x); | |
a85d226b | 1256 | return; |
9878760c RK |
1257 | |
1258 | default: | |
1259 | output_operand_lossage ("invalid %%xn code"); | |
1260 | } | |
1261 | } | |
1262 | \f | |
1263 | /* Print the address of an operand. */ | |
1264 | ||
1265 | void | |
1266 | print_operand_address (file, x) | |
1267 | FILE *file; | |
1268 | register rtx x; | |
1269 | { | |
1270 | if (GET_CODE (x) == REG) | |
1271 | fprintf (file, "0(%d)", REGNO (x)); | |
1272 | else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST) | |
1273 | { | |
1274 | output_addr_const (file, x); | |
1875cc88 JW |
1275 | /* When TARGET_MINIMAL_TOC, use the indirected toc table pointer instead |
1276 | of the toc pointer. */ | |
1277 | if (TARGET_MINIMAL_TOC) | |
1278 | fprintf (file, "(30)"); | |
1279 | else | |
1280 | fprintf (file, "(2)"); | |
9878760c RK |
1281 | } |
1282 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG) | |
1283 | { | |
1284 | if (REGNO (XEXP (x, 0)) == 0) | |
1285 | fprintf (file, "%d,%d", REGNO (XEXP (x, 1)), REGNO (XEXP (x, 0))); | |
1286 | else | |
1287 | fprintf (file, "%d,%d", REGNO (XEXP (x, 0)), REGNO (XEXP (x, 1))); | |
1288 | } | |
1289 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
1290 | fprintf (file, "%d(%d)", INTVAL (XEXP (x, 1)), REGNO (XEXP (x, 0))); | |
1291 | else | |
1292 | abort (); | |
1293 | } | |
1294 | \f | |
1295 | /* This page contains routines that are used to determine what the function | |
1296 | prologue and epilogue code will do and write them out. */ | |
1297 | ||
1298 | /* Return the first fixed-point register that is required to be saved. 32 if | |
1299 | none. */ | |
1300 | ||
1301 | int | |
1302 | first_reg_to_save () | |
1303 | { | |
1304 | int first_reg; | |
1305 | ||
1306 | /* Find lowest numbered live register. */ | |
1307 | for (first_reg = 13; first_reg <= 31; first_reg++) | |
1308 | if (regs_ever_live[first_reg]) | |
1309 | break; | |
1310 | ||
e165f3f0 RK |
1311 | /* If profiling, then we must save/restore every register that contains |
1312 | a parameter before/after the .mcount call. Use registers from 30 down | |
1313 | to 23 to do this. Don't use the frame pointer in reg 31. | |
1314 | ||
1315 | For now, save enough room for all of the parameter registers. */ | |
1316 | if (profile_flag) | |
1317 | if (first_reg > 23) | |
1318 | first_reg = 23; | |
1319 | ||
9878760c RK |
1320 | return first_reg; |
1321 | } | |
1322 | ||
1323 | /* Similar, for FP regs. */ | |
1324 | ||
1325 | int | |
1326 | first_fp_reg_to_save () | |
1327 | { | |
1328 | int first_reg; | |
1329 | ||
1330 | /* Find lowest numbered live register. */ | |
1331 | for (first_reg = 14 + 32; first_reg <= 63; first_reg++) | |
1332 | if (regs_ever_live[first_reg]) | |
1333 | break; | |
1334 | ||
1335 | return first_reg; | |
1336 | } | |
1337 | ||
1338 | /* Return 1 if we need to save CR. */ | |
1339 | ||
1340 | int | |
1341 | must_save_cr () | |
1342 | { | |
1343 | return regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72]; | |
1344 | } | |
1345 | ||
1346 | /* Compute the size of the save area in the stack, including the space for | |
1347 | the fixed area. */ | |
1348 | ||
1349 | int | |
1350 | rs6000_sa_size () | |
1351 | { | |
1352 | int size; | |
9878760c RK |
1353 | |
1354 | /* We have the six fixed words, plus the size of the register save | |
1355 | areas, rounded to a double-word. */ | |
1356 | size = 6 + (32 - first_reg_to_save ()) + (64 - first_fp_reg_to_save ()) * 2; | |
1357 | if (size & 1) | |
1358 | size++; | |
1359 | ||
1360 | return size * 4; | |
1361 | } | |
1362 | ||
1363 | /* Return non-zero if this function makes calls. */ | |
1364 | ||
1365 | int | |
1366 | rs6000_makes_calls () | |
1367 | { | |
1368 | rtx insn; | |
1369 | ||
0c61c946 RK |
1370 | /* If we are profiling, we will be making a call to mcount. */ |
1371 | if (profile_flag) | |
1372 | return 1; | |
1373 | ||
9878760c RK |
1374 | for (insn = get_insns (); insn; insn = next_insn (insn)) |
1375 | if (GET_CODE (insn) == CALL_INSN) | |
1376 | return 1; | |
1377 | ||
1378 | return 0; | |
1379 | } | |
1380 | ||
1381 | /* Return non-zero if this function needs to push space on the stack. */ | |
1382 | ||
1383 | int | |
1384 | rs6000_pushes_stack () | |
1385 | { | |
1386 | int total_size = (rs6000_sa_size () + get_frame_size () | |
1387 | + current_function_outgoing_args_size); | |
1388 | ||
1389 | /* We need to push the stack if a frame pointer is needed (because the | |
1390 | stack might be dynamically adjusted), if we are debugging, if the | |
1391 | total stack size is more than 220 bytes, or if we make calls. */ | |
1392 | ||
1393 | return (frame_pointer_needed || write_symbols != NO_DEBUG | |
1394 | || total_size > 220 | |
1395 | || rs6000_makes_calls ()); | |
1396 | } | |
1397 | ||
1398 | /* Write function prologue. */ | |
1399 | ||
1400 | void | |
1401 | output_prolog (file, size) | |
1402 | FILE *file; | |
1403 | int size; | |
1404 | { | |
1405 | int first_reg = first_reg_to_save (); | |
1406 | int must_push = rs6000_pushes_stack (); | |
1407 | int first_fp_reg = first_fp_reg_to_save (); | |
1408 | int basic_size = rs6000_sa_size (); | |
1409 | int total_size = (basic_size + size + current_function_outgoing_args_size); | |
1410 | ||
1411 | /* Round size to multiple of 8 bytes. */ | |
1412 | total_size = (total_size + 7) & ~7; | |
1413 | ||
1414 | /* Write .extern for any function we will call to save and restore fp | |
1415 | values. */ | |
1416 | if (first_fp_reg < 62) | |
1417 | fprintf (file, "\t.extern ._savef%d\n\t.extern ._restf%d\n", | |
1418 | first_fp_reg - 32, first_fp_reg - 32); | |
1419 | ||
1420 | /* Write .extern for truncation routines, if needed. */ | |
1421 | if (rs6000_trunc_used && ! trunc_defined) | |
1422 | { | |
e138174b ILT |
1423 | fprintf (file, "\t.extern .%s\n\t.extern .%s\n", |
1424 | RS6000_ITRUNC, RS6000_UITRUNC); | |
9878760c RK |
1425 | trunc_defined = 1; |
1426 | } | |
c764f757 RK |
1427 | /* Write .extern for AIX common mode routines, if needed. */ |
1428 | if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined) | |
1429 | { | |
1430 | fputs ("\t.extern __mulh\n" | |
1431 | "\t.extern __mull\n" | |
1432 | "\t.extern __divss\n" | |
1433 | "\t.extern __divus\n" | |
1434 | "\t.extern __quoss\n" | |
1435 | "\t.extern __quous\n", | |
1436 | file); | |
1437 | common_mode_defined = 1; | |
1438 | } | |
9878760c | 1439 | |
e165f3f0 RK |
1440 | /* If we have to call a function to save fpr's, or if we are doing profiling, |
1441 | then we will be using LR. */ | |
1442 | if (first_fp_reg < 62 || profile_flag) | |
9878760c RK |
1443 | regs_ever_live[65] = 1; |
1444 | ||
1445 | /* If we use the link register, get it into r0. */ | |
1446 | if (regs_ever_live[65]) | |
85638c0d | 1447 | asm_fprintf (file, "\tmflr 0\n"); |
9878760c RK |
1448 | |
1449 | /* If we need to save CR, put it into r12. */ | |
1450 | if (must_save_cr ()) | |
85638c0d | 1451 | asm_fprintf (file, "\tmfcr 12\n"); |
9878760c RK |
1452 | |
1453 | /* Do any required saving of fpr's. If only one or two to save, do it | |
53322b0c RK |
1454 | ourself. Otherwise, call function. Note that since they are statically |
1455 | linked, we do not need a nop following them. */ | |
9878760c | 1456 | if (first_fp_reg == 62) |
85638c0d | 1457 | asm_fprintf (file, "\tstfd 30,-16(1)\n\tstfd 31,-8(1)\n"); |
9878760c | 1458 | else if (first_fp_reg == 63) |
85638c0d | 1459 | asm_fprintf (file, "\tstfd 31,-8(1)\n"); |
9878760c | 1460 | else if (first_fp_reg != 64) |
85638c0d | 1461 | asm_fprintf (file, "\tbl ._savef%d\n", first_fp_reg - 32); |
9878760c RK |
1462 | |
1463 | /* Now save gpr's. */ | |
85638c0d RK |
1464 | if (! TARGET_POWER || first_reg == 31) |
1465 | { | |
1466 | int regno, loc; | |
1467 | ||
1468 | for (regno = first_reg, | |
1469 | loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8; | |
1470 | regno < 32; | |
1471 | regno++, loc += 4) | |
1472 | asm_fprintf (file, "\t{st|stw} %d,%d(1)\n", regno, loc); | |
1473 | } | |
1474 | ||
9878760c | 1475 | else if (first_reg != 32) |
85638c0d | 1476 | asm_fprintf (file, "\t{stm|stmw} %d,%d(1)\n", first_reg, |
9878760c RK |
1477 | - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8); |
1478 | ||
1479 | /* Save lr if we used it. */ | |
1480 | if (regs_ever_live[65]) | |
85638c0d | 1481 | asm_fprintf (file, "\t{st|stw} 0,8(1)\n"); |
9878760c RK |
1482 | |
1483 | /* Save CR if we use any that must be preserved. */ | |
1484 | if (must_save_cr ()) | |
85638c0d | 1485 | asm_fprintf (file, "\t{st|stw} 12,4(1)\n"); |
9878760c RK |
1486 | |
1487 | /* Update stack and set back pointer. */ | |
1488 | if (must_push) | |
1489 | { | |
1490 | if (total_size < 32767) | |
85638c0d | 1491 | asm_fprintf (file, "\t{stu|stwu} 1,%d(1)\n", - total_size); |
9878760c RK |
1492 | else |
1493 | { | |
85638c0d | 1494 | asm_fprintf (file, "\t{cau|addis} 0,0,%d\n\t{oril|ori} 0,0,%d\n", |
9878760c | 1495 | (total_size >> 16) & 0xffff, total_size & 0xffff); |
85638c0d RK |
1496 | asm_fprintf (file, "\t{sf|subfc} 12,0,1\n"); |
1497 | asm_fprintf (file, "\t{st|stw} 1,0(12)\n\t{oril|ori} 1,12,0\n"); | |
9878760c RK |
1498 | } |
1499 | } | |
1500 | ||
1501 | /* Set frame pointer, if needed. */ | |
1502 | if (frame_pointer_needed) | |
85638c0d | 1503 | asm_fprintf (file, "\t{oril|ori} 31,1,0\n"); |
1875cc88 JW |
1504 | |
1505 | /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the | |
1506 | TOC_TABLE address into register 30. */ | |
1507 | if (TARGET_MINIMAL_TOC && get_pool_size () != 0) | |
3daf36a4 ILT |
1508 | { |
1509 | char buf[100]; | |
1510 | ||
1511 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0); | |
1512 | asm_fprintf (file, "\t{l|lwz} 30,"); | |
1513 | assemble_name (file, buf); | |
1514 | asm_fprintf (file, "(2)\n"); | |
1515 | } | |
9878760c RK |
1516 | } |
1517 | ||
1518 | /* Write function epilogue. */ | |
1519 | ||
1520 | void | |
1521 | output_epilog (file, size) | |
1522 | FILE *file; | |
1523 | int size; | |
1524 | { | |
1525 | int first_reg = first_reg_to_save (); | |
1526 | int must_push = rs6000_pushes_stack (); | |
1527 | int first_fp_reg = first_fp_reg_to_save (); | |
1528 | int basic_size = rs6000_sa_size (); | |
1529 | int total_size = (basic_size + size + current_function_outgoing_args_size); | |
1530 | rtx insn = get_last_insn (); | |
1531 | ||
1532 | /* Round size to multiple of 8 bytes. */ | |
1533 | total_size = (total_size + 7) & ~7; | |
1534 | ||
1535 | /* If the last insn was a BARRIER, we don't have to write anything except | |
1536 | the trace table. */ | |
1537 | if (GET_CODE (insn) == NOTE) | |
1538 | insn = prev_nonnote_insn (insn); | |
1539 | if (insn == 0 || GET_CODE (insn) != BARRIER) | |
1540 | { | |
1541 | /* If we have a frame pointer, a call to alloca, or a large stack | |
1542 | frame, restore the old stack pointer using the backchain. Otherwise, | |
1543 | we know what size to update it with. */ | |
1544 | if (frame_pointer_needed || current_function_calls_alloca | |
1545 | || total_size > 32767) | |
85638c0d | 1546 | asm_fprintf (file, "\t{l|lwz} 1,0(1)\n"); |
9878760c | 1547 | else if (must_push) |
85638c0d | 1548 | asm_fprintf (file, "\t{ai|addic} 1,1,%d\n", total_size); |
9878760c | 1549 | |
b4ac57ab | 1550 | /* Get the old lr if we saved it. */ |
9878760c | 1551 | if (regs_ever_live[65]) |
85638c0d | 1552 | asm_fprintf (file, "\t{l|lwz} 0,8(1)\n"); |
9878760c RK |
1553 | |
1554 | /* Get the old cr if we saved it. */ | |
1555 | if (must_save_cr ()) | |
85638c0d | 1556 | asm_fprintf (file, "\t{l|lwz} 12,4(1)\n"); |
9878760c | 1557 | |
b4ac57ab RS |
1558 | /* Set LR here to try to overlap restores below. */ |
1559 | if (regs_ever_live[65]) | |
85638c0d | 1560 | asm_fprintf (file, "\tmtlr 0\n"); |
b4ac57ab | 1561 | |
9878760c | 1562 | /* Restore gpr's. */ |
85638c0d RK |
1563 | if (! TARGET_POWER || first_reg == 31) |
1564 | { | |
1565 | int regno, loc; | |
1566 | ||
1567 | for (regno = first_reg, | |
1568 | loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8; | |
1569 | regno < 32; | |
1570 | regno++, loc += 4) | |
1571 | asm_fprintf (file, "\t{l|lwz} %d,%d(1)\n", regno, loc); | |
1572 | } | |
1573 | ||
9878760c | 1574 | else if (first_reg != 32) |
85638c0d RK |
1575 | asm_fprintf (file, "\t{lm|lmw} %d,%d(1)\n", first_reg, |
1576 | - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8); | |
9878760c | 1577 | |
b4ac57ab | 1578 | /* Restore fpr's if we can do it without calling a function. */ |
9878760c | 1579 | if (first_fp_reg == 62) |
85638c0d | 1580 | asm_fprintf (file, "\tlfd 30,-16(1)\n\tlfd 31,-8(1)\n"); |
9878760c | 1581 | else if (first_fp_reg == 63) |
85638c0d | 1582 | asm_fprintf (file, "\tlfd 31,-8(1)\n"); |
9878760c | 1583 | |
28edebac RK |
1584 | /* If we saved cr, restore it here. Just those of cr2, cr3, and cr4 |
1585 | that were used. */ | |
9878760c | 1586 | if (must_save_cr ()) |
85638c0d RK |
1587 | asm_fprintf (file, "\tmtcrf %d,12\n", |
1588 | (regs_ever_live[70] != 0) * 0x20 | |
1589 | + (regs_ever_live[71] != 0) * 0x10 | |
1590 | + (regs_ever_live[72] != 0) * 0x8); | |
9878760c | 1591 | |
b4ac57ab RS |
1592 | /* If we have to restore more than two FP registers, branch to the |
1593 | restore function. It will return to our caller. */ | |
1594 | if (first_fp_reg < 62) | |
85638c0d | 1595 | asm_fprintf (file, "\tb ._restf%d\n", first_fp_reg - 32); |
b4ac57ab | 1596 | else |
85638c0d | 1597 | asm_fprintf (file, "\t{br|blr}\n"); |
9878760c | 1598 | } |
b4ac57ab | 1599 | |
9b30bae2 | 1600 | /* Output a traceback table here. See /usr/include/sys/debug.h for info |
314fc5a9 ILT |
1601 | on its format. |
1602 | ||
1603 | We don't output a traceback table if -finhibit-size-directive was | |
1604 | used. The documentation for -finhibit-size-directive reads | |
1605 | ``don't output a @code{.size} assembler directive, or anything | |
1606 | else that would cause trouble if the function is split in the | |
1607 | middle, and the two halves are placed at locations far apart in | |
1608 | memory.'' The traceback table has this property, since it | |
1609 | includes the offset from the start of the function to the | |
1610 | traceback table itself. */ | |
1611 | if (! flag_inhibit_size_directive) | |
9b30bae2 | 1612 | { |
314fc5a9 ILT |
1613 | char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); |
1614 | int fixed_parms, float_parms, parm_info; | |
1615 | int i; | |
1616 | ||
1617 | /* Need label immediately before tbtab, so we can compute its offset | |
1618 | from the function start. */ | |
1619 | if (*fname == '*') | |
1620 | ++fname; | |
1621 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); | |
1622 | ASM_OUTPUT_LABEL (file, fname); | |
1623 | ||
1624 | /* The .tbtab pseudo-op can only be used for the first eight | |
1625 | expressions, since it can't handle the possibly variable | |
1626 | length fields that follow. However, if you omit the optional | |
1627 | fields, the assembler outputs zeros for all optional fields | |
1628 | anyways, giving each variable length field is minimum length | |
1629 | (as defined in sys/debug.h). Thus we can not use the .tbtab | |
1630 | pseudo-op at all. */ | |
1631 | ||
1632 | /* An all-zero word flags the start of the tbtab, for debuggers | |
1633 | that have to find it by searching forward from the entry | |
1634 | point or from the current pc. */ | |
1635 | fprintf (file, "\t.long 0\n"); | |
1636 | ||
1637 | /* Tbtab format type. Use format type 0. */ | |
1638 | fprintf (file, "\t.byte 0,"); | |
1639 | ||
1640 | /* Language type. Unfortunately, there doesn't seem to be any | |
1641 | official way to get this info, so we use language_string. C | |
1642 | is 0. C++ is 9. No number defined for Obj-C, so use the | |
1643 | value for C for now. */ | |
1644 | if (! strcmp (language_string, "GNU C") | |
1645 | || ! strcmp (language_string, "GNU Obj-C")) | |
1646 | i = 0; | |
1647 | else if (! strcmp (language_string, "GNU F77")) | |
1648 | i = 1; | |
1649 | else if (! strcmp (language_string, "GNU Ada")) | |
1650 | i = 3; | |
1651 | else if (! strcmp (language_string, "GNU PASCAL")) | |
1652 | i = 2; | |
1653 | else if (! strcmp (language_string, "GNU C++")) | |
1654 | i = 9; | |
1655 | else | |
1656 | abort (); | |
1657 | fprintf (file, "%d,", i); | |
1658 | ||
1659 | /* 8 single bit fields: global linkage (not set for C extern linkage, | |
1660 | apparently a PL/I convention?), out-of-line epilogue/prologue, offset | |
1661 | from start of procedure stored in tbtab, internal function, function | |
1662 | has controlled storage, function has no toc, function uses fp, | |
1663 | function logs/aborts fp operations. */ | |
1664 | /* Assume that fp operations are used if any fp reg must be saved. */ | |
1665 | fprintf (file, "%d,", (1 << 5) | ((first_fp_reg != 64) << 1)); | |
1666 | ||
1667 | /* 6 bitfields: function is interrupt handler, name present in | |
1668 | proc table, function calls alloca, on condition directives | |
1669 | (controls stack walks, 3 bits), saves condition reg, saves | |
1670 | link reg. */ | |
1671 | /* The `function calls alloca' bit seems to be set whenever reg 31 is | |
1672 | set up as a frame pointer, even when there is no alloca call. */ | |
1673 | fprintf (file, "%d,", | |
1674 | ((1 << 6) | (frame_pointer_needed << 5) | |
1675 | | (must_save_cr () << 1) | (regs_ever_live[65]))); | |
1676 | ||
1677 | /* 3 bitfields: saves backchain, spare bit, number of fpr saved | |
1678 | (6 bits). */ | |
1679 | fprintf (file, "%d,", | |
1680 | (must_push << 7) | (64 - first_fp_reg_to_save ())); | |
1681 | ||
1682 | /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */ | |
1683 | fprintf (file, "%d,", (32 - first_reg_to_save ())); | |
1684 | ||
1685 | { | |
1686 | /* Compute the parameter info from the function decl argument | |
1687 | list. */ | |
1688 | tree decl; | |
1689 | int next_parm_info_bit; | |
1690 | ||
1691 | next_parm_info_bit = 31; | |
1692 | parm_info = 0; | |
1693 | fixed_parms = 0; | |
1694 | float_parms = 0; | |
1695 | ||
1696 | for (decl = DECL_ARGUMENTS (current_function_decl); | |
1697 | decl; decl = TREE_CHAIN (decl)) | |
1698 | { | |
1699 | rtx parameter = DECL_INCOMING_RTL (decl); | |
1700 | enum machine_mode mode = GET_MODE (parameter); | |
1701 | ||
1702 | if (GET_CODE (parameter) == REG) | |
1703 | { | |
1704 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
1705 | { | |
1706 | int bits; | |
1707 | ||
1708 | float_parms++; | |
1709 | ||
1710 | if (mode == SFmode) | |
1711 | bits = 0x2; | |
1712 | else if (mode == DFmode) | |
1713 | bits = 0x3; | |
1714 | else | |
1715 | abort (); | |
1716 | ||
1717 | /* If only one bit will fit, don't or in this entry. */ | |
1718 | if (next_parm_info_bit > 0) | |
1719 | parm_info |= (bits << (next_parm_info_bit - 1)); | |
1720 | next_parm_info_bit -= 2; | |
1721 | } | |
1722 | else | |
1723 | { | |
1724 | fixed_parms += ((GET_MODE_SIZE (mode) | |
1725 | + (UNITS_PER_WORD - 1)) | |
1726 | / UNITS_PER_WORD); | |
1727 | next_parm_info_bit -= 1; | |
1728 | } | |
1729 | } | |
1730 | } | |
1731 | } | |
1732 | ||
1733 | /* Number of fixed point parameters. */ | |
1734 | /* This is actually the number of words of fixed point parameters; thus | |
1735 | an 8 byte struct counts as 2; and thus the maximum value is 8. */ | |
1736 | fprintf (file, "%d,", fixed_parms); | |
1737 | ||
1738 | /* 2 bitfields: number of floating point parameters (7 bits), parameters | |
1739 | all on stack. */ | |
1740 | /* This is actually the number of fp registers that hold parameters; | |
1741 | and thus the maximum value is 13. */ | |
1742 | /* Set parameters on stack bit if parameters are not in their original | |
1743 | registers, regardless of whether they are on the stack? Xlc | |
1744 | seems to set the bit when not optimizing. */ | |
1745 | fprintf (file, "%d\n", ((float_parms << 1) | (! optimize))); | |
1746 | ||
1747 | /* Optional fields follow. Some are variable length. */ | |
1748 | ||
1749 | /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float, | |
1750 | 11 double float. */ | |
1751 | /* There is an entry for each parameter in a register, in the order that | |
1752 | they occur in the parameter list. Any intervening arguments on the | |
1753 | stack are ignored. If the list overflows a long (max possible length | |
1754 | 34 bits) then completely leave off all elements that don't fit. */ | |
1755 | /* Only emit this long if there was at least one parameter. */ | |
1756 | if (fixed_parms || float_parms) | |
1757 | fprintf (file, "\t.long %d\n", parm_info); | |
1758 | ||
1759 | /* Offset from start of code to tb table. */ | |
1760 | fprintf (file, "\t.long "); | |
1761 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); | |
1762 | RS6000_OUTPUT_BASENAME (file, fname); | |
1763 | fprintf (file, "-."); | |
1764 | RS6000_OUTPUT_BASENAME (file, fname); | |
1765 | fprintf (file, "\n"); | |
1766 | ||
1767 | /* Interrupt handler mask. */ | |
1768 | /* Omit this long, since we never set the interrupt handler bit | |
1769 | above. */ | |
1770 | ||
1771 | /* Number of CTL (controlled storage) anchors. */ | |
1772 | /* Omit this long, since the has_ctl bit is never set above. */ | |
1773 | ||
1774 | /* Displacement into stack of each CTL anchor. */ | |
1775 | /* Omit this list of longs, because there are no CTL anchors. */ | |
1776 | ||
1777 | /* Length of function name. */ | |
1778 | fprintf (file, "\t.short %d\n", strlen (fname)); | |
1779 | ||
1780 | /* Function name. */ | |
1781 | assemble_string (fname, strlen (fname)); | |
1782 | ||
1783 | /* Register for alloca automatic storage; this is always reg 31. | |
1784 | Only emit this if the alloca bit was set above. */ | |
1785 | if (frame_pointer_needed) | |
1786 | fprintf (file, "\t.byte 31\n"); | |
9b30bae2 | 1787 | } |
9878760c RK |
1788 | } |
1789 | \f | |
1790 | /* Output a TOC entry. We derive the entry name from what is | |
1791 | being written. */ | |
1792 | ||
1793 | void | |
1794 | output_toc (file, x, labelno) | |
1795 | FILE *file; | |
1796 | rtx x; | |
1797 | int labelno; | |
1798 | { | |
1799 | char buf[256]; | |
1800 | char *name = buf; | |
1801 | rtx base = x; | |
1802 | int offset = 0; | |
1803 | ||
1804 | ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno); | |
1805 | ||
37c37a57 RK |
1806 | /* Handle FP constants specially. Note that if we have a minimal |
1807 | TOC, things we put here aren't actually in the TOC, so we can allow | |
1808 | FP constants. */ | |
9878760c RK |
1809 | if (GET_CODE (x) == CONST_DOUBLE |
1810 | && GET_MODE (x) == DFmode | |
1811 | && TARGET_FLOAT_FORMAT == HOST_FLOAT_FORMAT | |
1812 | && BITS_PER_WORD == HOST_BITS_PER_INT | |
37c37a57 | 1813 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) |
9878760c | 1814 | { |
1875cc88 JW |
1815 | if (TARGET_MINIMAL_TOC) |
1816 | fprintf (file, "\t.long %d\n\t.long %d\n", | |
1817 | CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x)); | |
1818 | else | |
1819 | fprintf (file, "\t.tc FD_%x_%x[TC],%d,%d\n", | |
1820 | CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x), | |
1821 | CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x)); | |
9878760c RK |
1822 | return; |
1823 | } | |
1824 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode | |
37c37a57 | 1825 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) |
9878760c RK |
1826 | { |
1827 | rtx val = operand_subword (x, 0, 0, SFmode); | |
1828 | ||
1829 | if (val == 0 || GET_CODE (val) != CONST_INT) | |
1830 | abort (); | |
1831 | ||
1875cc88 JW |
1832 | if (TARGET_MINIMAL_TOC) |
1833 | fprintf (file, "\t.long %d\n", INTVAL (val)); | |
1834 | else | |
1835 | fprintf (file, "\t.tc FS_%x[TC],%d\n", INTVAL (val), INTVAL (val)); | |
9878760c RK |
1836 | return; |
1837 | } | |
1838 | ||
1839 | if (GET_CODE (x) == CONST) | |
1840 | { | |
1841 | base = XEXP (XEXP (x, 0), 0); | |
1842 | offset = INTVAL (XEXP (XEXP (x, 0), 1)); | |
1843 | } | |
1844 | ||
1845 | if (GET_CODE (base) == SYMBOL_REF) | |
1846 | name = XSTR (base, 0); | |
1847 | else if (GET_CODE (base) == LABEL_REF) | |
1848 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0))); | |
1849 | else if (GET_CODE (base) == CODE_LABEL) | |
1850 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base)); | |
1851 | else | |
1852 | abort (); | |
1853 | ||
1875cc88 JW |
1854 | if (TARGET_MINIMAL_TOC) |
1855 | fprintf (file, "\t.long "); | |
1856 | else | |
1857 | { | |
1858 | fprintf (file, "\t.tc "); | |
1859 | RS6000_OUTPUT_BASENAME (file, name); | |
9878760c | 1860 | |
1875cc88 JW |
1861 | if (offset < 0) |
1862 | fprintf (file, ".N%d", - offset); | |
1863 | else if (offset) | |
1864 | fprintf (file, ".P%d", offset); | |
9878760c | 1865 | |
1875cc88 JW |
1866 | fprintf (file, "[TC],"); |
1867 | } | |
9878760c RK |
1868 | output_addr_const (file, x); |
1869 | fprintf (file, "\n"); | |
1870 | } | |
1871 | \f | |
1872 | /* Output an assembler pseudo-op to write an ASCII string of N characters | |
1873 | starting at P to FILE. | |
1874 | ||
1875 | On the RS/6000, we have to do this using the .byte operation and | |
1876 | write out special characters outside the quoted string. | |
1877 | Also, the assembler is broken; very long strings are truncated, | |
1878 | so we must artificially break them up early. */ | |
1879 | ||
1880 | void | |
1881 | output_ascii (file, p, n) | |
1882 | FILE *file; | |
1883 | char *p; | |
1884 | int n; | |
1885 | { | |
1886 | char c; | |
1887 | int i, count_string; | |
1888 | char *for_string = "\t.byte \""; | |
1889 | char *for_decimal = "\t.byte "; | |
1890 | char *to_close = NULL; | |
1891 | ||
1892 | count_string = 0; | |
1893 | for (i = 0; i < n; i++) | |
1894 | { | |
1895 | c = *p++; | |
1896 | if (c >= ' ' && c < 0177) | |
1897 | { | |
1898 | if (for_string) | |
1899 | fputs (for_string, file); | |
1900 | putc (c, file); | |
1901 | ||
1902 | /* Write two quotes to get one. */ | |
1903 | if (c == '"') | |
1904 | { | |
1905 | putc (c, file); | |
1906 | ++count_string; | |
1907 | } | |
1908 | ||
1909 | for_string = NULL; | |
1910 | for_decimal = "\"\n\t.byte "; | |
1911 | to_close = "\"\n"; | |
1912 | ++count_string; | |
1913 | ||
1914 | if (count_string >= 512) | |
1915 | { | |
1916 | fputs (to_close, file); | |
1917 | ||
1918 | for_string = "\t.byte \""; | |
1919 | for_decimal = "\t.byte "; | |
1920 | to_close = NULL; | |
1921 | count_string = 0; | |
1922 | } | |
1923 | } | |
1924 | else | |
1925 | { | |
1926 | if (for_decimal) | |
1927 | fputs (for_decimal, file); | |
1928 | fprintf (file, "%d", c); | |
1929 | ||
1930 | for_string = "\n\t.byte \""; | |
1931 | for_decimal = ", "; | |
1932 | to_close = "\n"; | |
1933 | count_string = 0; | |
1934 | } | |
1935 | } | |
1936 | ||
1937 | /* Now close the string if we have written one. Then end the line. */ | |
1938 | if (to_close) | |
1939 | fprintf (file, to_close); | |
1940 | } | |
1941 | \f | |
1942 | /* Generate a unique section name for FILENAME for a section type | |
1943 | represented by SECTION_DESC. Output goes into BUF. | |
1944 | ||
1945 | SECTION_DESC can be any string, as long as it is different for each | |
1946 | possible section type. | |
1947 | ||
1948 | We name the section in the same manner as xlc. The name begins with an | |
1949 | underscore followed by the filename (after stripping any leading directory | |
11e5fe42 RK |
1950 | names) with the last period replaced by the string SECTION_DESC. If |
1951 | FILENAME does not contain a period, SECTION_DESC is appended to the end of | |
1952 | the name. */ | |
9878760c RK |
1953 | |
1954 | void | |
1955 | rs6000_gen_section_name (buf, filename, section_desc) | |
1956 | char **buf; | |
1957 | char *filename; | |
1958 | char *section_desc; | |
1959 | { | |
11e5fe42 | 1960 | char *q, *after_last_slash, *last_period; |
9878760c RK |
1961 | char *p; |
1962 | int len; | |
9878760c RK |
1963 | |
1964 | after_last_slash = filename; | |
1965 | for (q = filename; *q; q++) | |
11e5fe42 RK |
1966 | { |
1967 | if (*q == '/') | |
1968 | after_last_slash = q + 1; | |
1969 | else if (*q == '.') | |
1970 | last_period = q; | |
1971 | } | |
9878760c | 1972 | |
11e5fe42 | 1973 | len = strlen (after_last_slash) + strlen (section_desc) + 2; |
9878760c RK |
1974 | *buf = (char *) permalloc (len); |
1975 | ||
1976 | p = *buf; | |
1977 | *p++ = '_'; | |
1978 | ||
1979 | for (q = after_last_slash; *q; q++) | |
1980 | { | |
11e5fe42 | 1981 | if (q == last_period) |
9878760c RK |
1982 | { |
1983 | strcpy (p, section_desc); | |
1984 | p += strlen (section_desc); | |
9878760c RK |
1985 | } |
1986 | ||
1987 | else if (isalnum (*q)) | |
1988 | *p++ = *q; | |
1989 | } | |
1990 | ||
11e5fe42 | 1991 | if (last_period == 0) |
9878760c RK |
1992 | strcpy (p, section_desc); |
1993 | else | |
1994 | *p = '\0'; | |
1995 | } | |
e165f3f0 RK |
1996 | \f |
1997 | /* Write function profiler code. */ | |
1998 | ||
1999 | void | |
2000 | output_function_profiler (file, labelno) | |
2001 | FILE *file; | |
2002 | int labelno; | |
2003 | { | |
2004 | /* The last used parameter register. */ | |
2005 | int last_parm_reg; | |
2006 | int i, j; | |
3daf36a4 | 2007 | char buf[100]; |
e165f3f0 RK |
2008 | |
2009 | /* Set up a TOC entry for the profiler label. */ | |
2010 | toc_section (); | |
3daf36a4 ILT |
2011 | ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno); |
2012 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); | |
35fc1624 | 2013 | if (TARGET_MINIMAL_TOC) |
3daf36a4 ILT |
2014 | { |
2015 | fprintf (file, "\t.long "); | |
2016 | assemble_name (file, buf); | |
2017 | fprintf (file, "\n"); | |
2018 | } | |
35fc1624 | 2019 | else |
3daf36a4 ILT |
2020 | { |
2021 | fprintf (file, "\t.tc\t"); | |
2022 | assemble_name (file, buf); | |
2023 | fprintf (file, "[TC],"); | |
2024 | assemble_name (file, buf); | |
2025 | fprintf (file, "\n"); | |
2026 | } | |
e165f3f0 RK |
2027 | text_section (); |
2028 | ||
2029 | /* Figure out last used parameter register. The proper thing to do is | |
2030 | to walk incoming args of the function. A function might have live | |
2031 | parameter registers even if it has no incoming args. */ | |
2032 | ||
2033 | for (last_parm_reg = 10; | |
2034 | last_parm_reg > 2 && ! regs_ever_live [last_parm_reg]; | |
2035 | last_parm_reg--) | |
2036 | ; | |
2037 | ||
2038 | /* Save parameter registers in regs 23-30. Don't overwrite reg 31, since | |
2039 | it might be set up as the frame pointer. */ | |
2040 | ||
2041 | for (i = 3, j = 30; i <= last_parm_reg; i++, j--) | |
2042 | fprintf (file, "\tai %d,%d,0\n", j, i); | |
2043 | ||
2044 | /* Load location address into r3, and call mcount. */ | |
2045 | ||
3daf36a4 ILT |
2046 | ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno); |
2047 | fprintf (file, "\tl 3,"); | |
2048 | assemble_name (file, buf); | |
2049 | fprintf (file, "(2)\n\tbl .mcount\n"); | |
e165f3f0 RK |
2050 | |
2051 | /* Restore parameter registers. */ | |
2052 | ||
2053 | for (i = 3, j = 30; i <= last_parm_reg; i++, j--) | |
2054 | fprintf (file, "\tai %d,%d,0\n", i, j); | |
2055 | } | |
a251ffd0 TG |
2056 | |
2057 | /* Adjust the cost of a scheduling dependency. Return the new cost of | |
2058 | a dependency LINK or INSN on DEP_INSN. COST is the current cost. */ | |
2059 | ||
2060 | int | |
a06faf84 | 2061 | rs6000_adjust_cost (insn, link, dep_insn, cost) |
a251ffd0 TG |
2062 | rtx insn; |
2063 | rtx link; | |
2064 | rtx dep_insn; | |
2065 | int cost; | |
2066 | { | |
2067 | if (! recog_memoized (insn)) | |
2068 | return 0; | |
2069 | ||
2070 | if (REG_NOTE_KIND (link) != 0) | |
2071 | return 0; | |
2072 | ||
2073 | if (REG_NOTE_KIND (link) == 0) | |
2074 | { | |
2075 | /* Data dependency; DEP_INSN writes a register that INSN reads some | |
2076 | cycles later. */ | |
2077 | ||
2078 | /* Tell the first scheduling pass about the latency between a mtctr | |
2079 | and bctr (and mtlr and br/blr). The first scheduling pass will not | |
2080 | know about this latency since the mtctr instruction, which has the | |
2081 | latency associated to it, will be generated by reload. */ | |
2082 | if (get_attr_type (insn) == TYPE_JMPREG) | |
2083 | return TARGET_POWER ? 5 : 4; | |
2084 | ||
2085 | /* Fall out to return default cost. */ | |
2086 | } | |
2087 | ||
2088 | return cost; | |
2089 | } |