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