]>
Commit | Line | Data |
---|---|---|
7ce78e23 | 1 | /* Subroutines used for code generation on the Tilera TILEPro. |
3aea1f79 | 2 | Copyright (C) 2011-2014 Free Software Foundation, Inc. |
7ce78e23 | 3 | Contributed by Walter Lee (walt@tilera.com) |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU General Public License as published | |
9 | by the Free Software Foundation; either version 3, or (at your | |
10 | option) any later version. | |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT | |
13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | |
15 | License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GCC; see the file COPYING3. If not see | |
19 | <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | #include "config.h" | |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
24 | #include "tm.h" | |
25 | #include "rtl.h" | |
26 | #include "regs.h" | |
27 | #include "insn-config.h" | |
28 | #include "output.h" | |
29 | #include "insn-attr.h" | |
30 | #include "recog.h" | |
31 | #include "expr.h" | |
32 | #include "langhooks.h" | |
33 | #include "optabs.h" | |
34 | #include "sched-int.h" | |
35 | #include "sel-sched.h" | |
36 | #include "tm_p.h" | |
37 | #include "tm-constrs.h" | |
38 | #include "target.h" | |
39 | #include "target-def.h" | |
ea1760a3 | 40 | #include "function.h" |
7ce78e23 | 41 | #include "dwarf2.h" |
42 | #include "timevar.h" | |
bc3bf775 | 43 | #include "tree.h" |
bc61cadb | 44 | #include "pointer-set.h" |
45 | #include "hash-table.h" | |
46 | #include "vec.h" | |
47 | #include "ggc.h" | |
48 | #include "basic-block.h" | |
49 | #include "tree-ssa-alias.h" | |
50 | #include "internal-fn.h" | |
51 | #include "gimple-fold.h" | |
52 | #include "tree-eh.h" | |
53 | #include "gimple-expr.h" | |
54 | #include "is-a.h" | |
e795d6e1 | 55 | #include "gimple.h" |
9ed99284 | 56 | #include "stringpool.h" |
57 | #include "stor-layout.h" | |
58 | #include "varasm.h" | |
59 | #include "calls.h" | |
a8783bee | 60 | #include "gimplify.h" |
7ce78e23 | 61 | #include "cfgloop.h" |
62 | #include "tilepro-builtins.h" | |
63 | #include "tilepro-multiply.h" | |
64 | #include "diagnostic.h" | |
65 | ||
66 | /* SYMBOL_REF for GOT */ | |
67 | static GTY(()) rtx g_got_symbol = NULL; | |
68 | ||
69 | /* In case of a POST_INC or POST_DEC memory reference, we must report | |
70 | the mode of the memory reference from TARGET_PRINT_OPERAND to | |
71 | TARGET_PRINT_OPERAND_ADDRESS. */ | |
72 | static enum machine_mode output_memory_reference_mode; | |
73 | ||
74 | /* Report whether we're printing out the first address fragment of a | |
75 | POST_INC or POST_DEC memory reference, from TARGET_PRINT_OPERAND to | |
76 | TARGET_PRINT_OPERAND_ADDRESS. */ | |
77 | static bool output_memory_autoinc_first; | |
78 | ||
79 | \f | |
80 | ||
81 | /* Option handling */ | |
82 | ||
83 | /* Implement TARGET_OPTION_OVERRIDE. */ | |
84 | static void | |
85 | tilepro_option_override (void) | |
86 | { | |
87 | /* When modulo scheduling is enabled, we still rely on regular | |
88 | scheduler for bundling. */ | |
89 | if (flag_modulo_sched) | |
90 | flag_resched_modulo_sched = 1; | |
91 | } | |
92 | \f | |
93 | ||
94 | ||
95 | /* Implement TARGET_SCALAR_MODE_SUPPORTED_P. */ | |
96 | static bool | |
97 | tilepro_scalar_mode_supported_p (enum machine_mode mode) | |
98 | { | |
99 | switch (mode) | |
100 | { | |
101 | case QImode: | |
102 | case HImode: | |
103 | case SImode: | |
104 | case DImode: | |
105 | return true; | |
106 | ||
107 | case SFmode: | |
108 | case DFmode: | |
109 | return true; | |
110 | ||
111 | default: | |
112 | return false; | |
113 | } | |
114 | } | |
115 | ||
116 | ||
117 | /* Implement TARGET_VECTOR_MODE_SUPPORTED_P. */ | |
118 | static bool | |
119 | tile_vector_mode_supported_p (enum machine_mode mode) | |
120 | { | |
121 | return mode == V4QImode || mode == V2HImode; | |
122 | } | |
123 | ||
124 | ||
125 | /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */ | |
126 | static bool | |
127 | tilepro_cannot_force_const_mem (enum machine_mode mode ATTRIBUTE_UNUSED, | |
128 | rtx x ATTRIBUTE_UNUSED) | |
129 | { | |
130 | return true; | |
131 | } | |
132 | ||
133 | ||
134 | /* Implement TARGET_FUNCTION_OK_FOR_SIBCALL. */ | |
135 | static bool | |
136 | tilepro_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED) | |
137 | { | |
138 | return decl != NULL; | |
139 | } | |
140 | ||
141 | ||
142 | /* Implement TARGET_PASS_BY_REFERENCE. Variable sized types are | |
143 | passed by reference. */ | |
144 | static bool | |
145 | tilepro_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED, | |
146 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
147 | const_tree type, bool named ATTRIBUTE_UNUSED) | |
148 | { | |
149 | return (type && TYPE_SIZE (type) | |
150 | && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST); | |
151 | } | |
152 | ||
153 | ||
154 | /* Implement TARGET_RETURN_IN_MEMORY. */ | |
155 | static bool | |
156 | tilepro_return_in_memory (const_tree type, const_tree fndecl ATTRIBUTE_UNUSED) | |
157 | { | |
158 | return !IN_RANGE (int_size_in_bytes (type), | |
159 | 0, TILEPRO_NUM_RETURN_REGS * UNITS_PER_WORD); | |
160 | } | |
161 | ||
162 | ||
163 | /* Implement TARGET_FUNCTION_ARG_BOUNDARY. */ | |
164 | static unsigned int | |
165 | tilepro_function_arg_boundary (enum machine_mode mode, const_tree type) | |
166 | { | |
167 | unsigned int alignment; | |
168 | ||
169 | alignment = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode); | |
170 | if (alignment < PARM_BOUNDARY) | |
171 | alignment = PARM_BOUNDARY; | |
172 | if (alignment > STACK_BOUNDARY) | |
173 | alignment = STACK_BOUNDARY; | |
174 | return alignment; | |
175 | } | |
176 | ||
177 | ||
178 | /* Implement TARGET_FUNCTION_ARG. */ | |
179 | static rtx | |
180 | tilepro_function_arg (cumulative_args_t cum_v, | |
181 | enum machine_mode mode, | |
182 | const_tree type, bool named ATTRIBUTE_UNUSED) | |
183 | { | |
184 | CUMULATIVE_ARGS cum = *get_cumulative_args (cum_v); | |
185 | int byte_size = ((mode == BLKmode) | |
186 | ? int_size_in_bytes (type) : GET_MODE_SIZE (mode)); | |
187 | bool doubleword_aligned_p; | |
188 | ||
189 | if (cum >= TILEPRO_NUM_ARG_REGS) | |
190 | return NULL_RTX; | |
191 | ||
192 | /* See whether the argument has doubleword alignment. */ | |
193 | doubleword_aligned_p = | |
194 | tilepro_function_arg_boundary (mode, type) > BITS_PER_WORD; | |
195 | ||
196 | if (doubleword_aligned_p) | |
197 | cum += cum & 1; | |
198 | ||
199 | /* The ABI does not allow parameters to be passed partially in reg | |
200 | and partially in stack. */ | |
201 | if ((cum + (byte_size + UNITS_PER_WORD - 1) / UNITS_PER_WORD) | |
202 | > TILEPRO_NUM_ARG_REGS) | |
203 | return NULL_RTX; | |
204 | ||
205 | return gen_rtx_REG (mode, cum); | |
206 | } | |
207 | ||
208 | ||
209 | /* Implement TARGET_FUNCTION_ARG_ADVANCE. */ | |
210 | static void | |
211 | tilepro_function_arg_advance (cumulative_args_t cum_v, | |
212 | enum machine_mode mode, | |
213 | const_tree type, bool named ATTRIBUTE_UNUSED) | |
214 | { | |
215 | CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); | |
216 | ||
217 | int byte_size = ((mode == BLKmode) | |
218 | ? int_size_in_bytes (type) : GET_MODE_SIZE (mode)); | |
219 | int word_size = (byte_size + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
220 | bool doubleword_aligned_p; | |
221 | ||
222 | /* See whether the argument has doubleword alignment. */ | |
223 | doubleword_aligned_p = | |
224 | tilepro_function_arg_boundary (mode, type) > BITS_PER_WORD; | |
225 | ||
226 | if (doubleword_aligned_p) | |
227 | *cum += *cum & 1; | |
228 | ||
229 | /* If the current argument does not fit in the pretend_args space, | |
230 | skip over it. */ | |
231 | if (*cum < TILEPRO_NUM_ARG_REGS | |
232 | && *cum + word_size > TILEPRO_NUM_ARG_REGS) | |
233 | *cum = TILEPRO_NUM_ARG_REGS; | |
234 | ||
235 | *cum += word_size; | |
236 | } | |
237 | ||
238 | ||
239 | /* Implement TARGET_FUNCTION_VALUE. */ | |
240 | static rtx | |
241 | tilepro_function_value (const_tree valtype, const_tree fn_decl_or_type, | |
242 | bool outgoing ATTRIBUTE_UNUSED) | |
243 | { | |
244 | enum machine_mode mode; | |
245 | int unsigned_p; | |
246 | ||
247 | mode = TYPE_MODE (valtype); | |
248 | unsigned_p = TYPE_UNSIGNED (valtype); | |
249 | ||
250 | mode = promote_function_mode (valtype, mode, &unsigned_p, | |
251 | fn_decl_or_type, 1); | |
252 | ||
253 | return gen_rtx_REG (mode, 0); | |
254 | } | |
255 | ||
256 | ||
257 | /* Implement TARGET_LIBCALL_VALUE. */ | |
258 | static rtx | |
259 | tilepro_libcall_value (enum machine_mode mode, | |
260 | const_rtx fun ATTRIBUTE_UNUSED) | |
261 | { | |
262 | return gen_rtx_REG (mode, 0); | |
263 | } | |
264 | ||
265 | ||
266 | /* Implement FUNCTION_VALUE_REGNO_P. */ | |
267 | static bool | |
268 | tilepro_function_value_regno_p (const unsigned int regno) | |
269 | { | |
270 | return regno < TILEPRO_NUM_RETURN_REGS; | |
271 | } | |
272 | ||
273 | ||
274 | /* Implement TARGET_BUILD_BUILTIN_VA_LIST. */ | |
275 | static tree | |
276 | tilepro_build_builtin_va_list (void) | |
277 | { | |
278 | tree f_args, f_skip, record, type_decl; | |
279 | bool owp; | |
280 | ||
281 | record = lang_hooks.types.make_type (RECORD_TYPE); | |
282 | ||
283 | type_decl = build_decl (BUILTINS_LOCATION, TYPE_DECL, | |
284 | get_identifier ("__va_list_tag"), record); | |
285 | ||
286 | f_args = build_decl (BUILTINS_LOCATION, FIELD_DECL, | |
287 | get_identifier ("__args"), ptr_type_node); | |
288 | f_skip = build_decl (BUILTINS_LOCATION, FIELD_DECL, | |
289 | get_identifier ("__skip"), ptr_type_node); | |
290 | ||
291 | DECL_FIELD_CONTEXT (f_args) = record; | |
292 | ||
293 | DECL_FIELD_CONTEXT (f_skip) = record; | |
294 | ||
295 | TREE_CHAIN (record) = type_decl; | |
296 | TYPE_NAME (record) = type_decl; | |
297 | TYPE_FIELDS (record) = f_args; | |
298 | TREE_CHAIN (f_args) = f_skip; | |
299 | ||
300 | /* We know this is being padded and we want it too. It is an | |
301 | internal type so hide the warnings from the user. */ | |
302 | owp = warn_padded; | |
303 | warn_padded = false; | |
304 | ||
305 | layout_type (record); | |
306 | ||
307 | warn_padded = owp; | |
308 | ||
309 | /* The correct type is an array type of one element. */ | |
310 | return record; | |
311 | } | |
312 | ||
313 | ||
314 | /* Implement TARGET_EXPAND_BUILTIN_VA_START. */ | |
315 | static void | |
316 | tilepro_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED) | |
317 | { | |
318 | tree f_args, f_skip; | |
319 | tree args, skip, t; | |
320 | ||
321 | f_args = TYPE_FIELDS (TREE_TYPE (valist)); | |
322 | f_skip = TREE_CHAIN (f_args); | |
323 | ||
324 | args = | |
325 | build3 (COMPONENT_REF, TREE_TYPE (f_args), valist, f_args, NULL_TREE); | |
326 | skip = | |
327 | build3 (COMPONENT_REF, TREE_TYPE (f_skip), valist, f_skip, NULL_TREE); | |
328 | ||
329 | /* Find the __args area. */ | |
330 | t = make_tree (TREE_TYPE (args), virtual_incoming_args_rtx); | |
331 | t = fold_build_pointer_plus_hwi (t, | |
332 | UNITS_PER_WORD * | |
333 | (crtl->args.info - TILEPRO_NUM_ARG_REGS)); | |
334 | ||
335 | if (crtl->args.pretend_args_size > 0) | |
336 | t = fold_build_pointer_plus_hwi (t, -STACK_POINTER_OFFSET); | |
337 | ||
338 | t = build2 (MODIFY_EXPR, TREE_TYPE (args), args, t); | |
339 | TREE_SIDE_EFFECTS (t) = 1; | |
340 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
341 | ||
342 | /* Find the __skip area. */ | |
343 | t = make_tree (TREE_TYPE (skip), virtual_incoming_args_rtx); | |
344 | t = fold_build_pointer_plus_hwi (t, -STACK_POINTER_OFFSET); | |
345 | t = build2 (MODIFY_EXPR, TREE_TYPE (skip), skip, t); | |
346 | TREE_SIDE_EFFECTS (t) = 1; | |
347 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
348 | } | |
349 | ||
350 | ||
351 | /* Implement TARGET_SETUP_INCOMING_VARARGS. */ | |
352 | static void | |
353 | tilepro_setup_incoming_varargs (cumulative_args_t cum, | |
354 | enum machine_mode mode, | |
355 | tree type, int *pretend_args, int no_rtl) | |
356 | { | |
357 | CUMULATIVE_ARGS local_cum = *get_cumulative_args (cum); | |
358 | int first_reg; | |
359 | ||
360 | /* The caller has advanced CUM up to, but not beyond, the last named | |
361 | argument. Advance a local copy of CUM past the last "real" named | |
362 | argument, to find out how many registers are left over. */ | |
363 | targetm.calls.function_arg_advance (pack_cumulative_args (&local_cum), | |
364 | mode, type, true); | |
365 | first_reg = local_cum; | |
366 | ||
367 | if (local_cum < TILEPRO_NUM_ARG_REGS) | |
368 | { | |
369 | *pretend_args = UNITS_PER_WORD * (TILEPRO_NUM_ARG_REGS - first_reg); | |
370 | ||
371 | if (!no_rtl) | |
372 | { | |
373 | alias_set_type set = get_varargs_alias_set (); | |
374 | rtx tmp = | |
29c05e22 | 375 | gen_rtx_MEM (BLKmode, plus_constant (Pmode, \ |
376 | virtual_incoming_args_rtx, | |
7ce78e23 | 377 | -STACK_POINTER_OFFSET - |
378 | UNITS_PER_WORD * | |
379 | (TILEPRO_NUM_ARG_REGS - | |
380 | first_reg))); | |
381 | MEM_NOTRAP_P (tmp) = 1; | |
382 | set_mem_alias_set (tmp, set); | |
383 | move_block_from_reg (first_reg, tmp, | |
384 | TILEPRO_NUM_ARG_REGS - first_reg); | |
385 | } | |
386 | } | |
387 | else | |
388 | *pretend_args = 0; | |
389 | } | |
390 | ||
391 | ||
392 | /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. Gimplify va_arg by updating | |
393 | the va_list structure VALIST as required to retrieve an argument of | |
394 | type TYPE, and returning that argument. | |
395 | ||
396 | ret = va_arg(VALIST, TYPE); | |
397 | ||
398 | generates code equivalent to: | |
399 | ||
400 | paddedsize = (sizeof(TYPE) + 3) & -4; | |
401 | if ((VALIST.__args + paddedsize > VALIST.__skip) | |
402 | & (VALIST.__args <= VALIST.__skip)) | |
403 | addr = VALIST.__skip + STACK_POINTER_OFFSET; | |
404 | else | |
405 | addr = VALIST.__args; | |
406 | VALIST.__args = addr + paddedsize; | |
407 | ret = *(TYPE *)addr; */ | |
408 | static tree | |
409 | tilepro_gimplify_va_arg_expr (tree valist, tree type, gimple_seq * pre_p, | |
410 | gimple_seq * post_p ATTRIBUTE_UNUSED) | |
411 | { | |
412 | tree f_args, f_skip; | |
413 | tree args, skip; | |
414 | HOST_WIDE_INT size, rsize; | |
415 | tree addr, tmp; | |
416 | bool pass_by_reference_p; | |
417 | ||
418 | f_args = TYPE_FIELDS (va_list_type_node); | |
419 | f_skip = TREE_CHAIN (f_args); | |
420 | ||
421 | args = | |
422 | build3 (COMPONENT_REF, TREE_TYPE (f_args), valist, f_args, NULL_TREE); | |
423 | skip = | |
424 | build3 (COMPONENT_REF, TREE_TYPE (f_skip), valist, f_skip, NULL_TREE); | |
425 | ||
426 | addr = create_tmp_var (ptr_type_node, "va_arg"); | |
427 | ||
428 | /* if an object is dynamically sized, a pointer to it is passed | |
429 | instead of the object itself. */ | |
430 | pass_by_reference_p = pass_by_reference (NULL, TYPE_MODE (type), type, | |
431 | false); | |
432 | ||
433 | if (pass_by_reference_p) | |
434 | type = build_pointer_type (type); | |
435 | ||
436 | size = int_size_in_bytes (type); | |
437 | rsize = ((size + UNITS_PER_WORD - 1) / UNITS_PER_WORD) * UNITS_PER_WORD; | |
438 | ||
439 | /* If the alignment of the type is greater than the default for a | |
440 | parameter, align to STACK_BOUNDARY. */ | |
441 | if (TYPE_ALIGN (type) > PARM_BOUNDARY) | |
442 | { | |
443 | /* Assert the only case we generate code for: when | |
444 | stack boundary = 2 * parm boundary. */ | |
445 | gcc_assert (STACK_BOUNDARY == PARM_BOUNDARY * 2); | |
446 | ||
447 | tmp = build2 (BIT_AND_EXPR, sizetype, | |
448 | fold_convert (sizetype, unshare_expr (args)), | |
449 | size_int (PARM_BOUNDARY / 8)); | |
450 | tmp = build2 (POINTER_PLUS_EXPR, ptr_type_node, | |
451 | unshare_expr (args), tmp); | |
452 | ||
453 | gimplify_assign (unshare_expr (args), tmp, pre_p); | |
454 | } | |
455 | ||
456 | /* Build conditional expression to calculate addr. The expression | |
457 | will be gimplified later. */ | |
458 | tmp = fold_build_pointer_plus_hwi (unshare_expr (args), rsize); | |
459 | tmp = build2 (TRUTH_AND_EXPR, boolean_type_node, | |
460 | build2 (GT_EXPR, boolean_type_node, tmp, unshare_expr (skip)), | |
461 | build2 (LE_EXPR, boolean_type_node, unshare_expr (args), | |
462 | unshare_expr (skip))); | |
463 | ||
464 | tmp = build3 (COND_EXPR, ptr_type_node, tmp, | |
465 | build2 (POINTER_PLUS_EXPR, ptr_type_node, unshare_expr (skip), | |
466 | size_int (STACK_POINTER_OFFSET)), | |
467 | unshare_expr (args)); | |
468 | ||
469 | gimplify_assign (addr, tmp, pre_p); | |
470 | ||
471 | /* Update VALIST.__args. */ | |
472 | tmp = fold_build_pointer_plus_hwi (addr, rsize); | |
473 | gimplify_assign (unshare_expr (args), tmp, pre_p); | |
474 | ||
475 | addr = fold_convert (build_pointer_type (type), addr); | |
476 | ||
477 | if (pass_by_reference_p) | |
478 | addr = build_va_arg_indirect_ref (addr); | |
479 | ||
480 | return build_va_arg_indirect_ref (addr); | |
481 | } | |
482 | \f | |
483 | ||
484 | ||
485 | /* Implement TARGET_RTX_COSTS. */ | |
486 | static bool | |
487 | tilepro_rtx_costs (rtx x, int code, int outer_code, int opno, int *total, | |
488 | bool speed) | |
489 | { | |
490 | switch (code) | |
491 | { | |
492 | case CONST_INT: | |
493 | /* If this is an 8-bit constant, return zero since it can be | |
494 | used nearly anywhere with no cost. If it is a valid operand | |
495 | for an ADD or AND, likewise return 0 if we know it will be | |
496 | used in that context. Otherwise, return 2 since it might be | |
497 | used there later. All other constants take at least two | |
498 | insns. */ | |
499 | if (satisfies_constraint_I (x)) | |
500 | { | |
501 | *total = 0; | |
502 | return true; | |
503 | } | |
504 | else if (outer_code == PLUS && add_operand (x, VOIDmode)) | |
505 | { | |
506 | /* Slightly penalize large constants even though we can add | |
507 | them in one instruction, because it forces the use of | |
508 | 2-wide bundling mode. */ | |
509 | *total = 1; | |
510 | return true; | |
511 | } | |
512 | else if (move_operand (x, SImode)) | |
513 | { | |
514 | /* We can materialize in one move. */ | |
515 | *total = COSTS_N_INSNS (1); | |
516 | return true; | |
517 | } | |
518 | else | |
519 | { | |
520 | /* We can materialize in two moves. */ | |
521 | *total = COSTS_N_INSNS (2); | |
522 | return true; | |
523 | } | |
524 | ||
525 | return false; | |
526 | ||
527 | case CONST: | |
528 | case LABEL_REF: | |
529 | case SYMBOL_REF: | |
530 | *total = COSTS_N_INSNS (2); | |
531 | return true; | |
532 | ||
533 | case CONST_DOUBLE: | |
534 | *total = COSTS_N_INSNS (4); | |
535 | return true; | |
536 | ||
537 | case HIGH: | |
538 | *total = 0; | |
539 | return true; | |
540 | ||
541 | case MEM: | |
542 | /* If outer-code was a sign or zero extension, a cost of | |
543 | COSTS_N_INSNS (1) was already added in, so account for | |
544 | that. */ | |
545 | if (outer_code == ZERO_EXTEND || outer_code == SIGN_EXTEND) | |
546 | *total = COSTS_N_INSNS (1); | |
547 | else | |
548 | *total = COSTS_N_INSNS (2); | |
549 | return true; | |
550 | ||
551 | case PLUS: | |
552 | /* Convey that s[123]a are efficient. */ | |
553 | if (GET_CODE (XEXP (x, 0)) == MULT | |
554 | && cint_248_operand (XEXP (XEXP (x, 0), 1), VOIDmode)) | |
555 | { | |
556 | *total = (rtx_cost (XEXP (XEXP (x, 0), 0), | |
557 | (enum rtx_code) outer_code, opno, speed) | |
558 | + rtx_cost (XEXP (x, 1), | |
559 | (enum rtx_code) outer_code, opno, speed) | |
560 | + COSTS_N_INSNS (1)); | |
561 | return true; | |
562 | } | |
563 | return false; | |
564 | ||
565 | case MULT: | |
566 | *total = COSTS_N_INSNS (2); | |
567 | return false; | |
568 | ||
569 | case SIGN_EXTEND: | |
570 | case ZERO_EXTEND: | |
571 | if (outer_code == MULT) | |
572 | *total = 0; | |
573 | else | |
574 | *total = COSTS_N_INSNS (1); | |
575 | return false; | |
576 | ||
577 | case DIV: | |
578 | case UDIV: | |
579 | case MOD: | |
580 | case UMOD: | |
581 | /* These are handled by software and are very expensive. */ | |
582 | *total = COSTS_N_INSNS (100); | |
583 | return false; | |
584 | ||
585 | case UNSPEC: | |
586 | case UNSPEC_VOLATILE: | |
587 | { | |
588 | int num = XINT (x, 1); | |
589 | ||
590 | if (num <= TILEPRO_LAST_LATENCY_1_INSN) | |
591 | *total = COSTS_N_INSNS (1); | |
592 | else if (num <= TILEPRO_LAST_LATENCY_2_INSN) | |
593 | *total = COSTS_N_INSNS (2); | |
594 | else if (num > TILEPRO_LAST_LATENCY_INSN) | |
595 | { | |
596 | if (outer_code == PLUS) | |
597 | *total = 0; | |
598 | else | |
599 | *total = COSTS_N_INSNS (1); | |
600 | } | |
601 | else | |
602 | { | |
603 | switch (num) | |
604 | { | |
605 | case UNSPEC_BLOCKAGE: | |
606 | case UNSPEC_NETWORK_BARRIER: | |
607 | *total = 0; | |
608 | break; | |
609 | ||
610 | case UNSPEC_LNK_AND_LABEL: | |
611 | case UNSPEC_MF: | |
612 | case UNSPEC_NETWORK_RECEIVE: | |
613 | case UNSPEC_NETWORK_SEND: | |
614 | case UNSPEC_TLS_GD_ADD: | |
615 | *total = COSTS_N_INSNS (1); | |
616 | break; | |
617 | ||
618 | case UNSPEC_TLS_IE_LOAD: | |
619 | *total = COSTS_N_INSNS (2); | |
620 | break; | |
621 | ||
622 | case UNSPEC_SP_SET: | |
623 | *total = COSTS_N_INSNS (3); | |
624 | break; | |
625 | ||
626 | case UNSPEC_SP_TEST: | |
627 | *total = COSTS_N_INSNS (4); | |
628 | break; | |
629 | ||
630 | case UNSPEC_LATENCY_L2: | |
631 | *total = COSTS_N_INSNS (8); | |
632 | break; | |
633 | ||
634 | case UNSPEC_TLS_GD_CALL: | |
635 | *total = COSTS_N_INSNS (30); | |
636 | break; | |
637 | ||
638 | case UNSPEC_LATENCY_MISS: | |
639 | *total = COSTS_N_INSNS (80); | |
640 | break; | |
641 | ||
642 | default: | |
643 | *total = COSTS_N_INSNS (1); | |
644 | } | |
645 | } | |
646 | return true; | |
647 | } | |
648 | ||
649 | default: | |
650 | return false; | |
651 | } | |
652 | } | |
653 | \f | |
654 | ||
655 | ||
656 | /* Returns an SImode integer rtx with value VAL. */ | |
657 | static rtx | |
658 | gen_int_si (HOST_WIDE_INT val) | |
659 | { | |
660 | return gen_int_mode (val, SImode); | |
661 | } | |
662 | ||
663 | ||
664 | /* Create a temporary variable to hold a partial result, to enable | |
665 | CSE. */ | |
666 | static rtx | |
667 | create_temp_reg_if_possible (enum machine_mode mode, rtx default_reg) | |
668 | { | |
669 | return can_create_pseudo_p ()? gen_reg_rtx (mode) : default_reg; | |
670 | } | |
671 | ||
672 | ||
673 | /* Functions to save and restore machine-specific function data. */ | |
674 | static struct machine_function * | |
675 | tilepro_init_machine_status (void) | |
676 | { | |
25a27413 | 677 | return ggc_cleared_alloc<machine_function> (); |
7ce78e23 | 678 | } |
679 | ||
680 | ||
681 | /* Do anything needed before RTL is emitted for each function. */ | |
682 | void | |
683 | tilepro_init_expanders (void) | |
684 | { | |
685 | /* Arrange to initialize and mark the machine per-function | |
686 | status. */ | |
687 | init_machine_status = tilepro_init_machine_status; | |
688 | ||
689 | if (cfun && cfun->machine && flag_pic) | |
690 | { | |
691 | static int label_num = 0; | |
692 | ||
693 | char text_label_name[32]; | |
694 | ||
695 | struct machine_function *machine = cfun->machine; | |
696 | ||
697 | ASM_GENERATE_INTERNAL_LABEL (text_label_name, "L_PICLNK", label_num++); | |
698 | ||
699 | machine->text_label_symbol = | |
700 | gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (text_label_name)); | |
701 | ||
702 | machine->text_label_rtx = | |
703 | gen_rtx_REG (Pmode, TILEPRO_PIC_TEXT_LABEL_REGNUM); | |
704 | ||
705 | machine->got_rtx = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM); | |
706 | ||
707 | machine->calls_tls_get_addr = false; | |
708 | } | |
709 | } | |
710 | ||
711 | ||
712 | /* Return true if X contains a thread-local symbol. */ | |
713 | static bool | |
714 | tilepro_tls_referenced_p (rtx x) | |
715 | { | |
716 | if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS) | |
717 | x = XEXP (XEXP (x, 0), 0); | |
718 | ||
719 | if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x)) | |
720 | return true; | |
721 | ||
722 | /* That's all we handle in tilepro_legitimize_tls_address for | |
723 | now. */ | |
724 | return false; | |
725 | } | |
726 | ||
727 | ||
728 | /* Return true if X requires a scratch register. It is given that | |
729 | flag_pic is on and that X satisfies CONSTANT_P. */ | |
730 | static int | |
731 | tilepro_pic_address_needs_scratch (rtx x) | |
732 | { | |
733 | if (GET_CODE (x) == CONST | |
734 | && GET_CODE (XEXP (x, 0)) == PLUS | |
735 | && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF | |
736 | || GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF) | |
737 | && CONST_INT_P (XEXP (XEXP (x, 0), 1))) | |
738 | return true; | |
739 | ||
740 | return false; | |
741 | } | |
742 | ||
743 | ||
744 | /* Implement TARGET_LEGITIMATE_CONSTANT_P. This is all constants for | |
745 | which we are willing to load the value into a register via a move | |
746 | pattern. TLS cannot be treated as a constant because it can | |
747 | include a function call. */ | |
748 | static bool | |
749 | tilepro_legitimate_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx x) | |
750 | { | |
751 | switch (GET_CODE (x)) | |
752 | { | |
753 | case CONST: | |
754 | case SYMBOL_REF: | |
755 | return !tilepro_tls_referenced_p (x); | |
756 | ||
757 | default: | |
758 | return true; | |
759 | } | |
760 | } | |
761 | ||
762 | ||
763 | /* Return true if the constant value X is a legitimate general operand | |
764 | when generating PIC code. It is given that flag_pic is on and that | |
765 | X satisfies CONSTANT_P. */ | |
766 | bool | |
767 | tilepro_legitimate_pic_operand_p (rtx x) | |
768 | { | |
769 | if (tilepro_pic_address_needs_scratch (x)) | |
770 | return false; | |
771 | ||
772 | if (tilepro_tls_referenced_p (x)) | |
773 | return false; | |
774 | ||
775 | return true; | |
776 | } | |
777 | ||
778 | ||
779 | /* Return true if the rtx X can be used as an address operand. */ | |
780 | static bool | |
781 | tilepro_legitimate_address_p (enum machine_mode ARG_UNUSED (mode), rtx x, | |
782 | bool strict) | |
783 | { | |
784 | if (GET_CODE (x) == SUBREG) | |
785 | x = SUBREG_REG (x); | |
786 | ||
787 | switch (GET_CODE (x)) | |
788 | { | |
789 | case POST_INC: | |
790 | case POST_DEC: | |
791 | if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD) | |
792 | return false; | |
793 | ||
794 | x = XEXP (x, 0); | |
795 | break; | |
796 | ||
797 | case POST_MODIFY: | |
798 | if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD) | |
799 | return false; | |
800 | ||
801 | if (GET_CODE (XEXP (x, 1)) != PLUS) | |
802 | return false; | |
803 | ||
804 | if (!rtx_equal_p (XEXP (x, 0), XEXP (XEXP (x, 1), 0))) | |
805 | return false; | |
806 | ||
807 | if (!satisfies_constraint_I (XEXP (XEXP (x, 1), 1))) | |
808 | return false; | |
809 | ||
810 | x = XEXP (x, 0); | |
811 | break; | |
812 | ||
813 | case REG: | |
814 | break; | |
815 | ||
816 | default: | |
817 | return false; | |
818 | } | |
819 | ||
820 | /* Check if x is a valid reg. */ | |
821 | if (!REG_P (x)) | |
822 | return false; | |
823 | ||
824 | if (strict) | |
825 | return REGNO_OK_FOR_BASE_P (REGNO (x)); | |
826 | else | |
827 | return true; | |
828 | } | |
829 | ||
830 | ||
831 | /* Return the rtx containing SYMBOL_REF to the text label. */ | |
832 | static rtx | |
833 | tilepro_text_label_symbol (void) | |
834 | { | |
835 | return cfun->machine->text_label_symbol; | |
836 | } | |
837 | ||
838 | ||
839 | /* Return the register storing the value of the text label. */ | |
840 | static rtx | |
841 | tilepro_text_label_rtx (void) | |
842 | { | |
843 | return cfun->machine->text_label_rtx; | |
844 | } | |
845 | ||
846 | ||
847 | /* Return the register storing the value of the global offset | |
848 | table. */ | |
849 | static rtx | |
850 | tilepro_got_rtx (void) | |
851 | { | |
852 | return cfun->machine->got_rtx; | |
853 | } | |
854 | ||
855 | ||
856 | /* Return the SYMBOL_REF for _GLOBAL_OFFSET_TABLE_. */ | |
857 | static rtx | |
858 | tilepro_got_symbol (void) | |
859 | { | |
860 | if (g_got_symbol == NULL) | |
861 | g_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_"); | |
862 | ||
863 | return g_got_symbol; | |
864 | } | |
865 | ||
866 | ||
867 | /* Return a reference to the got to be used by tls references. */ | |
868 | static rtx | |
869 | tilepro_tls_got (void) | |
870 | { | |
871 | rtx temp; | |
872 | if (flag_pic) | |
873 | { | |
874 | crtl->uses_pic_offset_table = 1; | |
875 | return tilepro_got_rtx (); | |
876 | } | |
877 | ||
878 | temp = gen_reg_rtx (Pmode); | |
879 | emit_move_insn (temp, tilepro_got_symbol ()); | |
880 | ||
881 | return temp; | |
882 | } | |
883 | ||
884 | ||
885 | /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute | |
886 | this (thread-local) address. */ | |
887 | static rtx | |
888 | tilepro_legitimize_tls_address (rtx addr) | |
889 | { | |
890 | rtx ret; | |
891 | ||
892 | gcc_assert (can_create_pseudo_p ()); | |
893 | ||
894 | if (GET_CODE (addr) == SYMBOL_REF) | |
895 | switch (SYMBOL_REF_TLS_MODEL (addr)) | |
896 | { | |
897 | case TLS_MODEL_GLOBAL_DYNAMIC: | |
898 | case TLS_MODEL_LOCAL_DYNAMIC: | |
899 | { | |
900 | rtx r0, temp1, temp2, temp3, got, last; | |
901 | ||
902 | ret = gen_reg_rtx (Pmode); | |
903 | r0 = gen_rtx_REG (Pmode, 0); | |
904 | temp1 = gen_reg_rtx (Pmode); | |
905 | temp2 = gen_reg_rtx (Pmode); | |
906 | temp3 = gen_reg_rtx (Pmode); | |
907 | ||
908 | got = tilepro_tls_got (); | |
909 | emit_insn (gen_tls_gd_addhi (temp1, got, addr)); | |
910 | emit_insn (gen_tls_gd_addlo (temp2, temp1, addr)); | |
911 | emit_move_insn (r0, temp2); | |
912 | emit_insn (gen_tls_gd_call (addr)); | |
913 | emit_move_insn (temp3, r0); | |
914 | last = emit_insn (gen_tls_gd_add (ret, temp3, addr)); | |
915 | set_unique_reg_note (last, REG_EQUAL, copy_rtx (addr)); | |
916 | break; | |
917 | } | |
918 | case TLS_MODEL_INITIAL_EXEC: | |
919 | { | |
920 | rtx temp1, temp2, temp3, got, last; | |
921 | ||
922 | ret = gen_reg_rtx (Pmode); | |
923 | temp1 = gen_reg_rtx (Pmode); | |
924 | temp2 = gen_reg_rtx (Pmode); | |
925 | temp3 = gen_reg_rtx (Pmode); | |
926 | ||
927 | got = tilepro_tls_got (); | |
928 | emit_insn (gen_tls_ie_addhi (temp1, got, addr)); | |
929 | emit_insn (gen_tls_ie_addlo (temp2, temp1, addr)); | |
930 | emit_insn (gen_tls_ie_load (temp3, temp2, addr)); | |
931 | last = | |
932 | emit_move_insn(ret, | |
933 | gen_rtx_PLUS (Pmode, | |
934 | gen_rtx_REG (Pmode, | |
935 | THREAD_POINTER_REGNUM), | |
936 | temp3)); | |
937 | set_unique_reg_note (last, REG_EQUAL, copy_rtx (addr)); | |
938 | break; | |
939 | } | |
940 | case TLS_MODEL_LOCAL_EXEC: | |
941 | { | |
942 | rtx temp1, last; | |
943 | ||
944 | ret = gen_reg_rtx (Pmode); | |
945 | temp1 = gen_reg_rtx (Pmode); | |
946 | ||
947 | emit_insn (gen_tls_le_addhi (temp1, | |
948 | gen_rtx_REG (Pmode, | |
949 | THREAD_POINTER_REGNUM), | |
950 | addr)); | |
951 | last = emit_insn (gen_tls_le_addlo (ret, temp1, addr)); | |
952 | set_unique_reg_note (last, REG_EQUAL, copy_rtx (addr)); | |
953 | break; | |
954 | } | |
955 | default: | |
956 | gcc_unreachable (); | |
957 | } | |
958 | else if (GET_CODE (addr) == CONST) | |
959 | { | |
960 | rtx base, offset; | |
961 | ||
962 | gcc_assert (GET_CODE (XEXP (addr, 0)) == PLUS); | |
963 | ||
964 | base = tilepro_legitimize_tls_address (XEXP (XEXP (addr, 0), 0)); | |
965 | offset = XEXP (XEXP (addr, 0), 1); | |
966 | ||
967 | base = force_operand (base, NULL_RTX); | |
968 | ret = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, offset)); | |
969 | } | |
970 | else | |
971 | gcc_unreachable (); | |
972 | ||
973 | return ret; | |
974 | } | |
975 | ||
976 | ||
977 | /* Legitimize PIC addresses. If the address is already | |
978 | position-independent, we return ORIG. Newly generated | |
979 | position-independent addresses go into a reg. This is REG if | |
980 | nonzero, otherwise we allocate register(s) as necessary. */ | |
981 | static rtx | |
982 | tilepro_legitimize_pic_address (rtx orig, | |
983 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
984 | rtx reg) | |
985 | { | |
986 | if (GET_CODE (orig) == SYMBOL_REF) | |
987 | { | |
988 | rtx address, pic_ref; | |
989 | ||
990 | if (reg == 0) | |
991 | { | |
992 | gcc_assert (can_create_pseudo_p ()); | |
993 | reg = gen_reg_rtx (Pmode); | |
994 | } | |
995 | ||
996 | if (SYMBOL_REF_LOCAL_P (orig)) | |
997 | { | |
998 | /* If not during reload, allocate another temp reg here for | |
999 | loading in the address, so that these instructions can be | |
1000 | optimized properly. */ | |
1001 | rtx temp_reg = create_temp_reg_if_possible (Pmode, reg); | |
1002 | rtx text_label_symbol = tilepro_text_label_symbol (); | |
1003 | rtx text_label_rtx = tilepro_text_label_rtx (); | |
1004 | ||
1005 | emit_insn (gen_addli_pcrel (temp_reg, text_label_rtx, orig, | |
1006 | text_label_symbol)); | |
1007 | emit_insn (gen_auli_pcrel (temp_reg, temp_reg, orig, | |
1008 | text_label_symbol)); | |
1009 | ||
1010 | /* Note: this is conservative. We use the text_label but we | |
1011 | don't use the pic_offset_table. However, in some cases | |
1012 | we may need the pic_offset_table (see | |
1013 | tilepro_fixup_pcrel_references). */ | |
1014 | crtl->uses_pic_offset_table = 1; | |
1015 | ||
1016 | address = temp_reg; | |
1017 | ||
1018 | emit_move_insn (reg, address); | |
1019 | return reg; | |
1020 | } | |
1021 | else | |
1022 | { | |
1023 | /* If not during reload, allocate another temp reg here for | |
1024 | loading in the address, so that these instructions can be | |
1025 | optimized properly. */ | |
1026 | rtx temp_reg = create_temp_reg_if_possible (Pmode, reg); | |
1027 | ||
1028 | gcc_assert (flag_pic); | |
1029 | if (flag_pic == 1) | |
1030 | { | |
1031 | emit_insn (gen_add_got16 (temp_reg, | |
1032 | tilepro_got_rtx (), orig)); | |
1033 | } | |
1034 | else | |
1035 | { | |
1036 | rtx temp_reg2 = create_temp_reg_if_possible (Pmode, reg); | |
1037 | emit_insn (gen_addhi_got32 (temp_reg2, | |
1038 | tilepro_got_rtx (), orig)); | |
1039 | emit_insn (gen_addlo_got32 (temp_reg, temp_reg2, orig)); | |
1040 | } | |
1041 | ||
1042 | address = temp_reg; | |
1043 | ||
1044 | pic_ref = gen_const_mem (Pmode, address); | |
1045 | crtl->uses_pic_offset_table = 1; | |
1046 | emit_move_insn (reg, pic_ref); | |
1047 | /* The following put a REG_EQUAL note on this insn, so that | |
1048 | it can be optimized by loop. But it causes the label to | |
1049 | be optimized away. */ | |
1050 | /* set_unique_reg_note (insn, REG_EQUAL, orig); */ | |
1051 | return reg; | |
1052 | } | |
1053 | } | |
1054 | else if (GET_CODE (orig) == CONST) | |
1055 | { | |
1056 | rtx base, offset; | |
1057 | ||
1058 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
1059 | && XEXP (XEXP (orig, 0), 0) == tilepro_got_rtx ()) | |
1060 | return orig; | |
1061 | ||
1062 | if (reg == 0) | |
1063 | { | |
1064 | gcc_assert (can_create_pseudo_p ()); | |
1065 | reg = gen_reg_rtx (Pmode); | |
1066 | } | |
1067 | ||
1068 | gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS); | |
1069 | base = tilepro_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, | |
1070 | reg); | |
1071 | offset = | |
1072 | tilepro_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode, | |
1073 | base == reg ? 0 : reg); | |
1074 | ||
1075 | if (CONST_INT_P (offset)) | |
1076 | { | |
1077 | if (can_create_pseudo_p ()) | |
1078 | offset = force_reg (Pmode, offset); | |
1079 | else | |
1080 | /* If we reach here, then something is seriously | |
1081 | wrong. */ | |
1082 | gcc_unreachable (); | |
1083 | } | |
1084 | ||
1085 | if (can_create_pseudo_p ()) | |
1086 | return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, offset)); | |
1087 | else | |
1088 | gcc_unreachable (); | |
1089 | } | |
1090 | else if (GET_CODE (orig) == LABEL_REF) | |
1091 | { | |
1092 | rtx address, temp_reg; | |
1093 | rtx text_label_symbol; | |
1094 | rtx text_label_rtx; | |
1095 | ||
1096 | if (reg == 0) | |
1097 | { | |
1098 | gcc_assert (can_create_pseudo_p ()); | |
1099 | reg = gen_reg_rtx (Pmode); | |
1100 | } | |
1101 | ||
1102 | /* If not during reload, allocate another temp reg here for | |
1103 | loading in the address, so that these instructions can be | |
1104 | optimized properly. */ | |
1105 | temp_reg = create_temp_reg_if_possible (Pmode, reg); | |
1106 | text_label_symbol = tilepro_text_label_symbol (); | |
1107 | text_label_rtx = tilepro_text_label_rtx (); | |
1108 | ||
1109 | emit_insn (gen_addli_pcrel (temp_reg, text_label_rtx, orig, | |
1110 | text_label_symbol)); | |
1111 | emit_insn (gen_auli_pcrel (temp_reg, temp_reg, orig, | |
1112 | text_label_symbol)); | |
1113 | ||
1114 | /* Note: this is conservative. We use the text_label but we | |
1115 | don't use the pic_offset_table. */ | |
1116 | crtl->uses_pic_offset_table = 1; | |
1117 | ||
1118 | address = temp_reg; | |
1119 | ||
1120 | emit_move_insn (reg, address); | |
1121 | ||
1122 | return reg; | |
1123 | } | |
1124 | ||
1125 | return orig; | |
1126 | } | |
1127 | ||
1128 | ||
1129 | /* Implement TARGET_LEGITIMIZE_ADDRESS. */ | |
1130 | static rtx | |
1131 | tilepro_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, | |
1132 | enum machine_mode mode) | |
1133 | { | |
1134 | if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD | |
1135 | && symbolic_operand (x, Pmode) && tilepro_tls_referenced_p (x)) | |
1136 | { | |
1137 | return tilepro_legitimize_tls_address (x); | |
1138 | } | |
1139 | else if (flag_pic) | |
1140 | { | |
1141 | return tilepro_legitimize_pic_address (x, mode, 0); | |
1142 | } | |
1143 | else | |
1144 | return x; | |
1145 | } | |
1146 | ||
1147 | ||
1148 | /* Implement TARGET_DELEGITIMIZE_ADDRESS. */ | |
1149 | static rtx | |
1150 | tilepro_delegitimize_address (rtx x) | |
1151 | { | |
1152 | x = delegitimize_mem_from_attrs (x); | |
1153 | ||
1154 | if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == UNSPEC) | |
1155 | { | |
1156 | switch (XINT (XEXP (x, 0), 1)) | |
1157 | { | |
1158 | case UNSPEC_PCREL_SYM: | |
1159 | case UNSPEC_GOT16_SYM: | |
1160 | case UNSPEC_GOT32_SYM: | |
1161 | case UNSPEC_TLS_GD: | |
1162 | case UNSPEC_TLS_IE: | |
1163 | x = XVECEXP (XEXP (x, 0), 0, 0); | |
1164 | break; | |
1165 | } | |
1166 | } | |
1167 | ||
1168 | return x; | |
1169 | } | |
1170 | ||
1171 | ||
1172 | /* Emit code to load the PIC register. */ | |
1173 | static void | |
1174 | load_pic_register (bool delay_pic_helper ATTRIBUTE_UNUSED) | |
1175 | { | |
1176 | int orig_flag_pic = flag_pic; | |
1177 | ||
1178 | rtx got_symbol = tilepro_got_symbol (); | |
1179 | rtx text_label_symbol = tilepro_text_label_symbol (); | |
1180 | rtx text_label_rtx = tilepro_text_label_rtx (); | |
1181 | flag_pic = 0; | |
1182 | ||
1183 | emit_insn (gen_insn_lnk_and_label (text_label_rtx, text_label_symbol)); | |
1184 | ||
1185 | emit_insn (gen_addli_pcrel (tilepro_got_rtx (), | |
1186 | text_label_rtx, got_symbol, text_label_symbol)); | |
1187 | ||
1188 | emit_insn (gen_auli_pcrel (tilepro_got_rtx (), | |
1189 | tilepro_got_rtx (), | |
1190 | got_symbol, text_label_symbol)); | |
1191 | ||
1192 | flag_pic = orig_flag_pic; | |
1193 | ||
1194 | /* Need to emit this whether or not we obey regdecls, since | |
1195 | setjmp/longjmp can cause life info to screw up. ??? In the case | |
1196 | where we don't obey regdecls, this is not sufficient since we may | |
1197 | not fall out the bottom. */ | |
1198 | emit_use (tilepro_got_rtx ()); | |
1199 | } | |
1200 | ||
1201 | ||
1202 | /* Return the simd variant of the constant NUM of mode MODE, by | |
1203 | replicating it to fill an interger of mode SImode. NUM is first | |
1204 | truncated to fit in MODE. */ | |
1205 | rtx | |
1206 | tilepro_simd_int (rtx num, enum machine_mode mode) | |
1207 | { | |
1208 | HOST_WIDE_INT n = 0; | |
1209 | ||
1210 | gcc_assert (CONST_INT_P (num)); | |
1211 | ||
1212 | n = INTVAL (num); | |
1213 | ||
1214 | switch (mode) | |
1215 | { | |
1216 | case QImode: | |
1217 | n = 0x01010101 * (n & 0x000000FF); | |
1218 | break; | |
1219 | case HImode: | |
1220 | n = 0x00010001 * (n & 0x0000FFFF); | |
1221 | break; | |
1222 | case SImode: | |
1223 | break; | |
1224 | case DImode: | |
1225 | break; | |
1226 | default: | |
1227 | gcc_unreachable (); | |
1228 | } | |
1229 | ||
1230 | return gen_int_si (n); | |
1231 | } | |
1232 | ||
1233 | ||
1234 | /* Split one or more DImode RTL references into pairs of SImode | |
1235 | references. The RTL can be REG, offsettable MEM, integer constant, | |
1236 | or CONST_DOUBLE. "operands" is a pointer to an array of DImode RTL | |
1237 | to split and "num" is its length. lo_half and hi_half are output | |
1238 | arrays that parallel "operands". */ | |
1239 | void | |
1240 | split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[]) | |
1241 | { | |
1242 | while (num--) | |
1243 | { | |
1244 | rtx op = operands[num]; | |
1245 | ||
1246 | /* simplify_subreg refuse to split volatile memory addresses, | |
1247 | but we still have to handle it. */ | |
1248 | if (MEM_P (op)) | |
1249 | { | |
1250 | lo_half[num] = adjust_address (op, SImode, 0); | |
1251 | hi_half[num] = adjust_address (op, SImode, 4); | |
1252 | } | |
1253 | else | |
1254 | { | |
1255 | lo_half[num] = simplify_gen_subreg (SImode, op, | |
1256 | GET_MODE (op) == VOIDmode | |
1257 | ? DImode : GET_MODE (op), 0); | |
1258 | hi_half[num] = simplify_gen_subreg (SImode, op, | |
1259 | GET_MODE (op) == VOIDmode | |
1260 | ? DImode : GET_MODE (op), 4); | |
1261 | } | |
1262 | } | |
1263 | } | |
1264 | ||
1265 | ||
1266 | /* Returns true iff val can be moved into a register in one | |
1267 | instruction. And if it can, it emits the code to move the | |
1268 | constant. | |
1269 | ||
1270 | If three_wide_only is true, this insists on an instruction that | |
1271 | works in a bundle containing three instructions. */ | |
1272 | static bool | |
1273 | expand_set_cint32_one_inst (rtx dest_reg, | |
1274 | HOST_WIDE_INT val, bool three_wide_only) | |
1275 | { | |
1276 | val = trunc_int_for_mode (val, SImode); | |
1277 | ||
1278 | if (val == trunc_int_for_mode (val, QImode)) | |
1279 | { | |
1280 | /* Success! */ | |
1281 | emit_move_insn (dest_reg, GEN_INT (val)); | |
1282 | return true; | |
1283 | } | |
1284 | else if (!three_wide_only) | |
1285 | { | |
1286 | rtx imm_op = GEN_INT (val); | |
1287 | ||
1288 | if (satisfies_constraint_J (imm_op) | |
1289 | || satisfies_constraint_K (imm_op) | |
1290 | || satisfies_constraint_N (imm_op) | |
1291 | || satisfies_constraint_P (imm_op)) | |
1292 | { | |
1293 | emit_move_insn (dest_reg, imm_op); | |
1294 | return true; | |
1295 | } | |
1296 | } | |
1297 | ||
1298 | return false; | |
1299 | } | |
1300 | ||
1301 | ||
1302 | /* Implement SImode rotatert. */ | |
1303 | static HOST_WIDE_INT | |
1304 | rotate_right (HOST_WIDE_INT n, int count) | |
1305 | { | |
1306 | unsigned HOST_WIDE_INT x = n & 0xFFFFFFFF; | |
1307 | if (count == 0) | |
1308 | return x; | |
1309 | return ((x >> count) | (x << (32 - count))) & 0xFFFFFFFF; | |
1310 | } | |
1311 | ||
1312 | ||
1313 | /* Return true iff n contains exactly one contiguous sequence of 1 | |
1314 | bits, possibly wrapping around from high bits to low bits. */ | |
1315 | bool | |
1316 | tilepro_bitfield_operand_p (HOST_WIDE_INT n, int *first_bit, int *last_bit) | |
1317 | { | |
1318 | int i; | |
1319 | ||
1320 | if (n == 0) | |
1321 | return false; | |
1322 | ||
1323 | for (i = 0; i < 32; i++) | |
1324 | { | |
1325 | unsigned HOST_WIDE_INT x = rotate_right (n, i); | |
1326 | if (!(x & 1)) | |
1327 | continue; | |
1328 | ||
1329 | /* See if x is a power of two minus one, i.e. only consecutive 1 | |
1330 | bits starting from bit 0. */ | |
1331 | if ((x & (x + 1)) == 0) | |
1332 | { | |
1333 | if (first_bit != NULL) | |
1334 | *first_bit = i; | |
1335 | if (last_bit != NULL) | |
1336 | *last_bit = (i + exact_log2 (x ^ (x >> 1))) & 31; | |
1337 | ||
1338 | return true; | |
1339 | } | |
1340 | } | |
1341 | ||
1342 | return false; | |
1343 | } | |
1344 | ||
1345 | ||
1346 | /* Create code to move the CONST_INT value in src_val to dest_reg. */ | |
1347 | static void | |
1348 | expand_set_cint32 (rtx dest_reg, rtx src_val) | |
1349 | { | |
1350 | HOST_WIDE_INT val; | |
1351 | int leading_zeroes, trailing_zeroes; | |
1352 | int lower, upper; | |
1353 | int three_wide_only; | |
1354 | rtx temp; | |
1355 | ||
1356 | gcc_assert (CONST_INT_P (src_val)); | |
1357 | val = trunc_int_for_mode (INTVAL (src_val), SImode); | |
1358 | ||
1359 | /* See if we can generate the constant in one instruction. */ | |
1360 | if (expand_set_cint32_one_inst (dest_reg, val, false)) | |
1361 | return; | |
1362 | ||
1363 | /* Create a temporary variable to hold a partial result, to enable | |
1364 | CSE. */ | |
1365 | temp = create_temp_reg_if_possible (SImode, dest_reg); | |
1366 | ||
1367 | leading_zeroes = 31 - floor_log2 (val & 0xFFFFFFFF); | |
1368 | trailing_zeroes = exact_log2 (val & -val); | |
1369 | ||
1370 | lower = trunc_int_for_mode (val, HImode); | |
1371 | upper = trunc_int_for_mode ((val - lower) >> 16, HImode); | |
1372 | ||
1373 | /* First try all three-wide instructions that generate a constant | |
1374 | (i.e. movei) followed by various shifts and rotates. If none of | |
1375 | those work, try various two-wide ways of generating a constant | |
1376 | followed by various shifts and rotates. */ | |
1377 | for (three_wide_only = 1; three_wide_only >= 0; three_wide_only--) | |
1378 | { | |
1379 | int count; | |
1380 | ||
1381 | if (expand_set_cint32_one_inst (temp, val >> trailing_zeroes, | |
1382 | three_wide_only)) | |
1383 | { | |
1384 | /* 0xFFFFA500 becomes: | |
1385 | movei temp, 0xFFFFFFA5 | |
1386 | shli dest, temp, 8 */ | |
1387 | emit_move_insn (dest_reg, | |
1388 | gen_rtx_ASHIFT (SImode, temp, | |
1389 | GEN_INT (trailing_zeroes))); | |
1390 | return; | |
1391 | } | |
1392 | ||
1393 | if (expand_set_cint32_one_inst (temp, val << leading_zeroes, | |
1394 | three_wide_only)) | |
1395 | { | |
1396 | /* 0x7FFFFFFF becomes: | |
1397 | movei temp, -2 | |
1398 | shri dest, temp, 1 */ | |
1399 | emit_move_insn (dest_reg, | |
1400 | gen_rtx_LSHIFTRT (SImode, temp, | |
1401 | GEN_INT (leading_zeroes))); | |
1402 | return; | |
1403 | } | |
1404 | ||
1405 | /* Try rotating a one-instruction immediate, since rotate is | |
1406 | 3-wide. */ | |
1407 | for (count = 1; count < 32; count++) | |
1408 | { | |
1409 | HOST_WIDE_INT r = rotate_right (val, count); | |
1410 | if (expand_set_cint32_one_inst (temp, r, three_wide_only)) | |
1411 | { | |
1412 | /* 0xFFA5FFFF becomes: | |
1413 | movei temp, 0xFFFFFFA5 | |
1414 | rli dest, temp, 16 */ | |
1415 | emit_move_insn (dest_reg, | |
1416 | gen_rtx_ROTATE (SImode, temp, GEN_INT (count))); | |
1417 | return; | |
1418 | } | |
1419 | } | |
1420 | ||
1421 | if (lower == trunc_int_for_mode (lower, QImode)) | |
1422 | { | |
1423 | /* We failed to use two 3-wide instructions, but the low 16 | |
1424 | bits are a small number so just use a 2-wide + 3-wide | |
1425 | auli + addi pair rather than anything more exotic. | |
1426 | ||
1427 | 0x12340056 becomes: | |
1428 | auli temp, zero, 0x1234 | |
1429 | addi dest, temp, 0x56 */ | |
1430 | break; | |
1431 | } | |
1432 | } | |
1433 | ||
1434 | /* Fallback case: use a auli + addli/addi pair. */ | |
1435 | emit_move_insn (temp, GEN_INT (upper << 16)); | |
1436 | emit_move_insn (dest_reg, (gen_rtx_PLUS (SImode, temp, GEN_INT (lower)))); | |
1437 | } | |
1438 | ||
1439 | ||
1440 | /* Load OP1, a 32-bit constant, into OP0, a register. We know it | |
1441 | can't be done in one insn when we get here, the move expander | |
1442 | guarantees this. */ | |
1443 | void | |
1444 | tilepro_expand_set_const32 (rtx op0, rtx op1) | |
1445 | { | |
1446 | enum machine_mode mode = GET_MODE (op0); | |
1447 | rtx temp; | |
1448 | ||
1449 | if (CONST_INT_P (op1)) | |
1450 | { | |
1451 | /* TODO: I don't know if we want to split large constants now, | |
1452 | or wait until later (with a define_split). | |
1453 | ||
1454 | Does splitting early help CSE? Does it harm other | |
1455 | optimizations that might fold loads? */ | |
1456 | expand_set_cint32 (op0, op1); | |
1457 | } | |
1458 | else | |
1459 | { | |
1460 | temp = create_temp_reg_if_possible (mode, op0); | |
1461 | ||
1462 | /* A symbol, emit in the traditional way. */ | |
1463 | emit_move_insn (temp, gen_rtx_HIGH (mode, op1)); | |
1464 | emit_move_insn (op0, gen_rtx_LO_SUM (mode, temp, op1)); | |
1465 | } | |
1466 | } | |
1467 | ||
1468 | ||
1469 | /* Expand a move instruction. Return true if all work is done. */ | |
1470 | bool | |
1471 | tilepro_expand_mov (enum machine_mode mode, rtx *operands) | |
1472 | { | |
1473 | /* Handle sets of MEM first. */ | |
1474 | if (MEM_P (operands[0])) | |
1475 | { | |
1476 | if (can_create_pseudo_p ()) | |
1477 | operands[0] = validize_mem (operands[0]); | |
1478 | ||
1479 | if (reg_or_0_operand (operands[1], mode)) | |
1480 | return false; | |
1481 | ||
1482 | if (!reload_in_progress) | |
1483 | operands[1] = force_reg (mode, operands[1]); | |
1484 | } | |
1485 | ||
1486 | /* Fixup TLS cases. */ | |
1487 | if (CONSTANT_P (operands[1]) && tilepro_tls_referenced_p (operands[1])) | |
1488 | { | |
1489 | operands[1] = tilepro_legitimize_tls_address (operands[1]); | |
1490 | return false; | |
1491 | } | |
1492 | ||
1493 | /* Fixup PIC cases. */ | |
1494 | if (flag_pic && CONSTANT_P (operands[1])) | |
1495 | { | |
1496 | if (tilepro_pic_address_needs_scratch (operands[1])) | |
1497 | operands[1] = tilepro_legitimize_pic_address (operands[1], mode, 0); | |
1498 | ||
1499 | if (symbolic_operand (operands[1], mode)) | |
1500 | { | |
1501 | operands[1] = tilepro_legitimize_pic_address (operands[1], | |
1502 | mode, | |
1503 | (reload_in_progress ? | |
1504 | operands[0] : | |
1505 | NULL_RTX)); | |
1506 | return false; | |
1507 | } | |
1508 | } | |
1509 | ||
1510 | /* Fixup for UNSPEC addresses. */ | |
1511 | if (flag_pic | |
1512 | && GET_CODE (operands[1]) == HIGH | |
1513 | && GET_CODE (XEXP (operands[1], 0)) == CONST | |
1514 | && GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == UNSPEC) | |
1515 | { | |
1516 | rtx unspec = XEXP (XEXP (operands[1], 0), 0); | |
1517 | int unspec_num = XINT (unspec, 1); | |
1518 | if (unspec_num == UNSPEC_PCREL_SYM) | |
1519 | { | |
1520 | emit_insn (gen_auli_pcrel (operands[0], const0_rtx, | |
1521 | XVECEXP (unspec, 0, 0), | |
1522 | XVECEXP (unspec, 0, 1))); | |
1523 | return true; | |
1524 | } | |
1525 | else if (flag_pic == 2 && unspec_num == UNSPEC_GOT32_SYM) | |
1526 | { | |
1527 | emit_insn (gen_addhi_got32 (operands[0], const0_rtx, | |
1528 | XVECEXP (unspec, 0, 0))); | |
1529 | return true; | |
1530 | } | |
1531 | else if (HAVE_AS_TLS && unspec_num == UNSPEC_TLS_GD) | |
1532 | { | |
1533 | emit_insn (gen_tls_gd_addhi (operands[0], const0_rtx, | |
1534 | XVECEXP (unspec, 0, 0))); | |
1535 | return true; | |
1536 | } | |
1537 | else if (HAVE_AS_TLS && unspec_num == UNSPEC_TLS_IE) | |
1538 | { | |
1539 | emit_insn (gen_tls_ie_addhi (operands[0], const0_rtx, | |
1540 | XVECEXP (unspec, 0, 0))); | |
1541 | return true; | |
1542 | } | |
1543 | else if (HAVE_AS_TLS && unspec_num == UNSPEC_TLS_LE) | |
1544 | { | |
1545 | emit_insn (gen_tls_le_addhi (operands[0], const0_rtx, | |
1546 | XVECEXP (unspec, 0, 0))); | |
1547 | return true; | |
1548 | } | |
1549 | } | |
1550 | ||
1551 | /* Accept non-constants and valid constants unmodified. */ | |
1552 | if (!CONSTANT_P (operands[1]) | |
1553 | || GET_CODE (operands[1]) == HIGH || move_operand (operands[1], mode)) | |
1554 | return false; | |
1555 | ||
1556 | /* Split large integers. */ | |
1557 | if (GET_MODE_SIZE (mode) <= 4) | |
1558 | { | |
1559 | tilepro_expand_set_const32 (operands[0], operands[1]); | |
1560 | return true; | |
1561 | } | |
1562 | ||
1563 | return false; | |
1564 | } | |
1565 | ||
1566 | ||
1567 | /* Expand the "insv" pattern. */ | |
1568 | void | |
1569 | tilepro_expand_insv (rtx operands[4]) | |
1570 | { | |
1571 | rtx first_rtx = operands[2]; | |
1572 | HOST_WIDE_INT first = INTVAL (first_rtx); | |
1573 | HOST_WIDE_INT width = INTVAL (operands[1]); | |
1574 | rtx v = operands[3]; | |
1575 | ||
1576 | /* Shift the inserted bits into position. */ | |
1577 | if (first != 0) | |
1578 | { | |
1579 | if (CONST_INT_P (v)) | |
1580 | { | |
1581 | /* Shift the constant into mm position. */ | |
1582 | v = gen_int_si (INTVAL (v) << first); | |
1583 | } | |
1584 | else | |
1585 | { | |
1586 | /* Shift over the value to be inserted. */ | |
1587 | rtx tmp = gen_reg_rtx (SImode); | |
1588 | emit_insn (gen_ashlsi3 (tmp, v, first_rtx)); | |
1589 | v = tmp; | |
1590 | } | |
1591 | } | |
1592 | ||
1593 | /* Insert the shifted bits using an 'mm' insn. */ | |
1594 | emit_insn (gen_insn_mm (operands[0], v, operands[0], first_rtx, | |
1595 | GEN_INT (first + width - 1))); | |
1596 | } | |
1597 | ||
1598 | ||
1599 | /* Expand unaligned loads. */ | |
1600 | void | |
1601 | tilepro_expand_unaligned_load (rtx dest_reg, rtx mem, HOST_WIDE_INT bitsize, | |
1602 | HOST_WIDE_INT bit_offset, bool sign) | |
1603 | { | |
1604 | enum machine_mode mode; | |
1605 | rtx addr_lo, addr_hi; | |
1606 | rtx mem_lo, mem_hi, hi; | |
1607 | rtx mema, wide_result; | |
1608 | int last_byte_offset; | |
1609 | HOST_WIDE_INT byte_offset = bit_offset / BITS_PER_UNIT; | |
1610 | ||
1611 | mode = GET_MODE (dest_reg); | |
1612 | ||
1613 | hi = gen_reg_rtx (mode); | |
1614 | ||
1615 | if (bitsize == 2 * BITS_PER_UNIT && (bit_offset % BITS_PER_UNIT) == 0) | |
1616 | { | |
1617 | rtx lo; | |
1618 | ||
1619 | /* When just loading a two byte value, we can load the two bytes | |
1620 | individually and combine them efficiently. */ | |
1621 | ||
1622 | mem_lo = adjust_address (mem, QImode, byte_offset); | |
1623 | mem_hi = adjust_address (mem, QImode, byte_offset + 1); | |
1624 | ||
1625 | lo = gen_reg_rtx (mode); | |
1626 | emit_insn (gen_zero_extendqisi2 (lo, mem_lo)); | |
1627 | ||
1628 | if (sign) | |
1629 | { | |
1630 | rtx tmp = gen_reg_rtx (mode); | |
1631 | ||
1632 | /* Do a signed load of the second byte then shift and OR it | |
1633 | in. */ | |
1634 | emit_insn (gen_extendqisi2 (gen_lowpart (SImode, hi), mem_hi)); | |
1635 | emit_insn (gen_ashlsi3 (gen_lowpart (SImode, tmp), | |
1636 | gen_lowpart (SImode, hi), GEN_INT (8))); | |
1637 | emit_insn (gen_iorsi3 (gen_lowpart (SImode, dest_reg), | |
1638 | gen_lowpart (SImode, lo), | |
1639 | gen_lowpart (SImode, tmp))); | |
1640 | } | |
1641 | else | |
1642 | { | |
1643 | /* Do two unsigned loads and use intlb to interleave | |
1644 | them. */ | |
1645 | emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, hi), mem_hi)); | |
1646 | emit_insn (gen_insn_intlb (gen_lowpart (SImode, dest_reg), | |
1647 | gen_lowpart (SImode, hi), | |
1648 | gen_lowpart (SImode, lo))); | |
1649 | } | |
1650 | ||
1651 | return; | |
1652 | } | |
1653 | ||
1654 | mema = XEXP (mem, 0); | |
1655 | ||
1656 | /* AND addresses cannot be in any alias set, since they may | |
1657 | implicitly alias surrounding code. Ideally we'd have some alias | |
1658 | set that covered all types except those with alignment 8 or | |
1659 | higher. */ | |
29c05e22 | 1660 | addr_lo = force_reg (Pmode, plus_constant (Pmode, mema, byte_offset)); |
7ce78e23 | 1661 | mem_lo = change_address (mem, mode, |
1662 | gen_rtx_AND (Pmode, addr_lo, GEN_INT (-4))); | |
1663 | set_mem_alias_set (mem_lo, 0); | |
1664 | ||
1665 | /* Load the high word at an address that will not fault if the low | |
1666 | address is aligned and at the very end of a page. */ | |
1667 | last_byte_offset = (bit_offset + bitsize - 1) / BITS_PER_UNIT; | |
29c05e22 | 1668 | addr_hi = force_reg (Pmode, plus_constant (Pmode, mema, last_byte_offset)); |
7ce78e23 | 1669 | mem_hi = change_address (mem, mode, |
1670 | gen_rtx_AND (Pmode, addr_hi, GEN_INT (-4))); | |
1671 | set_mem_alias_set (mem_hi, 0); | |
1672 | ||
1673 | if (bitsize == 32) | |
1674 | { | |
1675 | addr_lo = make_safe_from (addr_lo, dest_reg); | |
1676 | wide_result = dest_reg; | |
1677 | } | |
1678 | else | |
1679 | { | |
1680 | wide_result = gen_reg_rtx (mode); | |
1681 | } | |
1682 | ||
1683 | /* Load hi first in case dest_reg is used in mema. */ | |
1684 | emit_move_insn (hi, mem_hi); | |
1685 | emit_move_insn (wide_result, mem_lo); | |
1686 | ||
1687 | emit_insn (gen_insn_dword_align (gen_lowpart (SImode, wide_result), | |
1688 | gen_lowpart (SImode, wide_result), | |
1689 | gen_lowpart (SImode, hi), addr_lo)); | |
1690 | ||
1691 | if (bitsize != 32) | |
1692 | { | |
1693 | rtx extracted = | |
1694 | extract_bit_field (gen_lowpart (SImode, wide_result), | |
1695 | bitsize, bit_offset % BITS_PER_UNIT, | |
3f71db40 | 1696 | !sign, gen_lowpart (SImode, dest_reg), |
7ce78e23 | 1697 | SImode, SImode); |
1698 | ||
1699 | if (extracted != dest_reg) | |
1700 | emit_move_insn (dest_reg, gen_lowpart (SImode, extracted)); | |
1701 | } | |
1702 | } | |
1703 | ||
1704 | ||
1705 | /* Expand unaligned stores. */ | |
1706 | static void | |
1707 | tilepro_expand_unaligned_store (rtx mem, rtx src, HOST_WIDE_INT bitsize, | |
1708 | HOST_WIDE_INT bit_offset) | |
1709 | { | |
1710 | HOST_WIDE_INT byte_offset = bit_offset / BITS_PER_UNIT; | |
1711 | HOST_WIDE_INT bytesize = bitsize / BITS_PER_UNIT; | |
1712 | HOST_WIDE_INT shift_amt; | |
1713 | HOST_WIDE_INT i; | |
1714 | rtx mem_addr; | |
1715 | rtx store_val; | |
1716 | ||
1717 | for (i = 0, shift_amt = 0; i < bytesize; i++, shift_amt += BITS_PER_UNIT) | |
1718 | { | |
1719 | mem_addr = adjust_address (mem, QImode, byte_offset + i); | |
1720 | ||
1721 | if (shift_amt) | |
1722 | { | |
1723 | store_val = expand_simple_binop (SImode, LSHIFTRT, | |
1724 | gen_lowpart (SImode, src), | |
1725 | GEN_INT (shift_amt), NULL, 1, | |
1726 | OPTAB_LIB_WIDEN); | |
1727 | store_val = gen_lowpart (QImode, store_val); | |
1728 | } | |
1729 | else | |
1730 | { | |
1731 | store_val = gen_lowpart (QImode, src); | |
1732 | } | |
1733 | ||
1734 | emit_move_insn (mem_addr, store_val); | |
1735 | } | |
1736 | } | |
1737 | ||
1738 | ||
1739 | /* Implement the movmisalign patterns. One of the operands is a | |
1740 | memory that is not naturally aligned. Emit instructions to load | |
1741 | it. */ | |
1742 | void | |
1743 | tilepro_expand_movmisalign (enum machine_mode mode, rtx *operands) | |
1744 | { | |
1745 | if (MEM_P (operands[1])) | |
1746 | { | |
1747 | rtx tmp; | |
1748 | ||
1749 | if (register_operand (operands[0], mode)) | |
1750 | tmp = operands[0]; | |
1751 | else | |
1752 | tmp = gen_reg_rtx (mode); | |
1753 | ||
1754 | tilepro_expand_unaligned_load (tmp, operands[1], | |
1755 | GET_MODE_BITSIZE (mode), 0, true); | |
1756 | ||
1757 | if (tmp != operands[0]) | |
1758 | emit_move_insn (operands[0], tmp); | |
1759 | } | |
1760 | else if (MEM_P (operands[0])) | |
1761 | { | |
1762 | if (!reg_or_0_operand (operands[1], mode)) | |
1763 | operands[1] = force_reg (mode, operands[1]); | |
1764 | ||
1765 | tilepro_expand_unaligned_store (operands[0], operands[1], | |
1766 | GET_MODE_BITSIZE (mode), 0); | |
1767 | } | |
1768 | else | |
1769 | gcc_unreachable (); | |
1770 | } | |
1771 | ||
1772 | ||
1773 | /* Implement the addsi3 pattern. */ | |
1774 | bool | |
1775 | tilepro_expand_addsi (rtx op0, rtx op1, rtx op2) | |
1776 | { | |
1777 | rtx temp; | |
1778 | HOST_WIDE_INT n; | |
1779 | HOST_WIDE_INT high; | |
1780 | ||
1781 | /* Skip anything that only takes one instruction. */ | |
1782 | if (add_operand (op2, SImode)) | |
1783 | return false; | |
1784 | ||
1785 | /* We can only optimize ints here (it should be impossible to get | |
1786 | here with any other type, but it is harmless to check. */ | |
1787 | if (!CONST_INT_P (op2)) | |
1788 | return false; | |
1789 | ||
1790 | temp = create_temp_reg_if_possible (SImode, op0); | |
1791 | n = INTVAL (op2); | |
1792 | high = (n + (n & 0x8000)) & ~0xffff; | |
1793 | ||
1794 | emit_move_insn (temp, gen_rtx_PLUS (SImode, op1, gen_int_si (high))); | |
1795 | emit_move_insn (op0, gen_rtx_PLUS (SImode, temp, gen_int_si (n - high))); | |
1796 | ||
1797 | return true; | |
1798 | } | |
1799 | ||
1800 | ||
1801 | /* Implement the allocate_stack pattern (alloca). */ | |
1802 | void | |
1803 | tilepro_allocate_stack (rtx op0, rtx op1) | |
1804 | { | |
1805 | /* Technically the correct way to initialize chain_loc is with | |
1806 | * gen_frame_mem() instead of gen_rtx_MEM(), but gen_frame_mem() | |
1807 | * sets the alias_set to that of a frame reference. Some of our | |
1808 | * tests rely on some unsafe assumption about when the chaining | |
1809 | * update is done, we need to be conservative about reordering the | |
1810 | * chaining instructions. | |
1811 | */ | |
1812 | rtx fp_addr = gen_reg_rtx (Pmode); | |
1813 | rtx fp_value = gen_reg_rtx (Pmode); | |
1814 | rtx fp_loc; | |
1815 | ||
1816 | emit_move_insn (fp_addr, gen_rtx_PLUS (Pmode, stack_pointer_rtx, | |
1817 | GEN_INT (UNITS_PER_WORD))); | |
1818 | ||
1819 | fp_loc = gen_frame_mem (Pmode, fp_addr); | |
1820 | ||
1821 | emit_move_insn (fp_value, fp_loc); | |
1822 | ||
1823 | op1 = force_reg (Pmode, op1); | |
1824 | ||
1825 | emit_move_insn (stack_pointer_rtx, | |
1826 | gen_rtx_MINUS (Pmode, stack_pointer_rtx, op1)); | |
1827 | ||
1828 | emit_move_insn (fp_addr, gen_rtx_PLUS (Pmode, stack_pointer_rtx, | |
1829 | GEN_INT (UNITS_PER_WORD))); | |
1830 | ||
1831 | fp_loc = gen_frame_mem (Pmode, fp_addr); | |
1832 | ||
1833 | emit_move_insn (fp_loc, fp_value); | |
1834 | ||
1835 | emit_move_insn (op0, virtual_stack_dynamic_rtx); | |
1836 | } | |
1837 | \f | |
1838 | ||
1839 | ||
1840 | /* Multiplies */ | |
1841 | ||
1842 | /* Returns the insn_code in ENTRY. */ | |
1843 | static enum insn_code | |
1844 | tilepro_multiply_get_opcode (const struct tilepro_multiply_insn_seq_entry | |
1845 | *entry) | |
1846 | { | |
1847 | return tilepro_multiply_insn_seq_decode_opcode[entry->compressed_opcode]; | |
1848 | } | |
1849 | ||
1850 | ||
1851 | /* Returns the length of the 'op' array. */ | |
1852 | static int | |
1853 | tilepro_multiply_get_num_ops (const struct tilepro_multiply_insn_seq *seq) | |
1854 | { | |
1855 | /* The array either uses all of its allocated slots or is terminated | |
1856 | by a bogus opcode. Either way, the array size is the index of the | |
1857 | last valid opcode plus one. */ | |
1858 | int i; | |
1859 | for (i = tilepro_multiply_insn_seq_MAX_OPERATIONS - 1; i >= 0; i--) | |
1860 | if (tilepro_multiply_get_opcode (&seq->op[i]) != CODE_FOR_nothing) | |
1861 | return i + 1; | |
1862 | ||
1863 | /* An empty array is not allowed. */ | |
1864 | gcc_unreachable (); | |
1865 | } | |
1866 | ||
1867 | ||
1868 | /* We precompute a number of expression trees for multiplying by | |
1869 | constants. This generates code for such an expression tree by | |
1870 | walking through the nodes in the tree (which are conveniently | |
1871 | pre-linearized) and emitting an instruction for each one. */ | |
1872 | static void | |
1873 | tilepro_expand_constant_multiply_given_sequence (rtx result, rtx src, | |
1874 | const struct | |
1875 | tilepro_multiply_insn_seq | |
1876 | *seq) | |
1877 | { | |
1878 | int i; | |
1879 | int num_ops; | |
1880 | ||
1881 | /* Keep track of the subexpressions computed so far, so later | |
1882 | instructions can refer to them. We seed the array with zero and | |
1883 | the value being multiplied. */ | |
1884 | int num_subexprs = 2; | |
1885 | rtx subexprs[tilepro_multiply_insn_seq_MAX_OPERATIONS + 2]; | |
1886 | subexprs[0] = const0_rtx; | |
1887 | subexprs[1] = src; | |
1888 | ||
1889 | /* Determine how many instructions we are going to generate. */ | |
1890 | num_ops = tilepro_multiply_get_num_ops (seq); | |
1891 | gcc_assert (num_ops > 0 | |
1892 | && num_ops <= tilepro_multiply_insn_seq_MAX_OPERATIONS); | |
1893 | ||
1894 | for (i = 0; i < num_ops; i++) | |
1895 | { | |
1896 | const struct tilepro_multiply_insn_seq_entry *entry = &seq->op[i]; | |
1897 | ||
1898 | /* Figure out where to store the output of this instruction. */ | |
1899 | const bool is_last_op = (i + 1 == num_ops); | |
1900 | rtx out = is_last_op ? result : gen_reg_rtx (SImode); | |
1901 | ||
1902 | enum insn_code opcode = tilepro_multiply_get_opcode (entry); | |
1903 | if (opcode == CODE_FOR_ashlsi3) | |
1904 | { | |
1905 | /* Handle shift by immediate. This is a special case because | |
1906 | the meaning of the second operand is a constant shift | |
1907 | count rather than an operand index. */ | |
1908 | ||
1909 | /* Make sure the shift count is in range. Zero should not | |
1910 | happen. */ | |
1911 | const int shift_count = entry->rhs; | |
1912 | gcc_assert (shift_count > 0 && shift_count < 32); | |
1913 | ||
1914 | /* Emit the actual instruction. */ | |
1915 | emit_insn (GEN_FCN (opcode) | |
1916 | (out, subexprs[entry->lhs], | |
1917 | gen_rtx_CONST_INT (SImode, shift_count))); | |
1918 | } | |
1919 | else | |
1920 | { | |
1921 | /* Handle a normal two-operand instruction, such as add or | |
1922 | s1a. */ | |
1923 | ||
1924 | /* Make sure we are referring to a previously computed | |
1925 | subexpression. */ | |
1926 | gcc_assert (entry->rhs < num_subexprs); | |
1927 | ||
1928 | /* Emit the actual instruction. */ | |
1929 | emit_insn (GEN_FCN (opcode) | |
1930 | (out, subexprs[entry->lhs], subexprs[entry->rhs])); | |
1931 | } | |
1932 | ||
1933 | /* Record this subexpression for use by later expressions. */ | |
1934 | subexprs[num_subexprs++] = out; | |
1935 | } | |
1936 | } | |
1937 | ||
1938 | ||
1939 | /* bsearch helper function. */ | |
1940 | static int | |
1941 | tilepro_compare_multipliers (const void *key, const void *t) | |
1942 | { | |
1943 | return *(const int *) key - | |
1944 | ((const struct tilepro_multiply_insn_seq *) t)->multiplier; | |
1945 | } | |
1946 | ||
1947 | ||
1948 | /* Returns the tilepro_multiply_insn_seq for multiplier, or NULL if | |
1949 | none exists. */ | |
1950 | static const struct tilepro_multiply_insn_seq * | |
1951 | tilepro_find_multiply_insn_seq_for_constant (int multiplier) | |
1952 | { | |
1953 | return ((const struct tilepro_multiply_insn_seq *) | |
1954 | bsearch (&multiplier, tilepro_multiply_insn_seq_table, | |
1955 | tilepro_multiply_insn_seq_table_size, | |
1956 | sizeof tilepro_multiply_insn_seq_table[0], | |
1957 | tilepro_compare_multipliers)); | |
1958 | } | |
1959 | ||
1960 | ||
1961 | /* Try to a expand constant multiply in SImode by looking it up in a | |
1962 | precompiled table. OP0 is the result operand, OP1 is the source | |
1963 | operand, and MULTIPLIER is the value of the constant. Return true | |
1964 | if it succeeds. */ | |
1965 | static bool | |
1966 | tilepro_expand_const_mulsi (rtx op0, rtx op1, int multiplier) | |
1967 | { | |
1968 | /* See if we have precomputed an efficient way to multiply by this | |
1969 | constant. */ | |
1970 | const struct tilepro_multiply_insn_seq *seq = | |
1971 | tilepro_find_multiply_insn_seq_for_constant (multiplier); | |
1972 | if (seq != NULL) | |
1973 | { | |
1974 | tilepro_expand_constant_multiply_given_sequence (op0, op1, seq); | |
1975 | return true; | |
1976 | } | |
1977 | else | |
1978 | return false; | |
1979 | } | |
1980 | ||
1981 | ||
1982 | /* Expand the mulsi pattern. */ | |
1983 | bool | |
1984 | tilepro_expand_mulsi (rtx op0, rtx op1, rtx op2) | |
1985 | { | |
1986 | if (CONST_INT_P (op2)) | |
1987 | { | |
1988 | HOST_WIDE_INT n = trunc_int_for_mode (INTVAL (op2), SImode); | |
1989 | return tilepro_expand_const_mulsi (op0, op1, n); | |
1990 | } | |
1991 | return false; | |
1992 | } | |
1993 | ||
1994 | ||
1995 | /* Expand a high multiply pattern in SImode. RESULT, OP1, OP2 are the | |
1996 | operands, and SIGN is true if it's a signed multiply, and false if | |
1997 | it's an unsigned multiply. */ | |
1998 | static void | |
1999 | tilepro_expand_high_multiply (rtx result, rtx op1, rtx op2, bool sign) | |
2000 | { | |
2001 | rtx tmp0 = gen_reg_rtx (SImode); | |
2002 | rtx tmp1 = gen_reg_rtx (SImode); | |
2003 | rtx tmp2 = gen_reg_rtx (SImode); | |
2004 | rtx tmp3 = gen_reg_rtx (SImode); | |
2005 | rtx tmp4 = gen_reg_rtx (SImode); | |
2006 | rtx tmp5 = gen_reg_rtx (SImode); | |
2007 | rtx tmp6 = gen_reg_rtx (SImode); | |
2008 | rtx tmp7 = gen_reg_rtx (SImode); | |
2009 | rtx tmp8 = gen_reg_rtx (SImode); | |
2010 | rtx tmp9 = gen_reg_rtx (SImode); | |
2011 | rtx tmp10 = gen_reg_rtx (SImode); | |
2012 | rtx tmp11 = gen_reg_rtx (SImode); | |
2013 | rtx tmp12 = gen_reg_rtx (SImode); | |
2014 | rtx tmp13 = gen_reg_rtx (SImode); | |
2015 | rtx result_lo = gen_reg_rtx (SImode); | |
2016 | ||
2017 | if (sign) | |
2018 | { | |
2019 | emit_insn (gen_insn_mulhl_su (tmp0, op1, op2)); | |
2020 | emit_insn (gen_insn_mulhl_su (tmp1, op2, op1)); | |
2021 | emit_insn (gen_insn_mulll_uu (tmp2, op1, op2)); | |
2022 | emit_insn (gen_insn_mulhh_ss (tmp3, op1, op2)); | |
2023 | } | |
2024 | else | |
2025 | { | |
2026 | emit_insn (gen_insn_mulhl_uu (tmp0, op1, op2)); | |
2027 | emit_insn (gen_insn_mulhl_uu (tmp1, op2, op1)); | |
2028 | emit_insn (gen_insn_mulll_uu (tmp2, op1, op2)); | |
2029 | emit_insn (gen_insn_mulhh_uu (tmp3, op1, op2)); | |
2030 | } | |
2031 | ||
2032 | emit_move_insn (tmp4, (gen_rtx_ASHIFT (SImode, tmp0, GEN_INT (16)))); | |
2033 | ||
2034 | emit_move_insn (tmp5, (gen_rtx_ASHIFT (SImode, tmp1, GEN_INT (16)))); | |
2035 | ||
2036 | emit_move_insn (tmp6, (gen_rtx_PLUS (SImode, tmp4, tmp5))); | |
2037 | emit_move_insn (result_lo, (gen_rtx_PLUS (SImode, tmp2, tmp6))); | |
2038 | ||
2039 | emit_move_insn (tmp7, gen_rtx_LTU (SImode, tmp6, tmp4)); | |
2040 | emit_move_insn (tmp8, gen_rtx_LTU (SImode, result_lo, tmp2)); | |
2041 | ||
2042 | if (sign) | |
2043 | { | |
2044 | emit_move_insn (tmp9, (gen_rtx_ASHIFTRT (SImode, tmp0, GEN_INT (16)))); | |
2045 | emit_move_insn (tmp10, (gen_rtx_ASHIFTRT (SImode, tmp1, GEN_INT (16)))); | |
2046 | } | |
2047 | else | |
2048 | { | |
2049 | emit_move_insn (tmp9, (gen_rtx_LSHIFTRT (SImode, tmp0, GEN_INT (16)))); | |
2050 | emit_move_insn (tmp10, (gen_rtx_LSHIFTRT (SImode, tmp1, GEN_INT (16)))); | |
2051 | } | |
2052 | ||
2053 | emit_move_insn (tmp11, (gen_rtx_PLUS (SImode, tmp3, tmp7))); | |
2054 | emit_move_insn (tmp12, (gen_rtx_PLUS (SImode, tmp8, tmp9))); | |
2055 | emit_move_insn (tmp13, (gen_rtx_PLUS (SImode, tmp11, tmp12))); | |
2056 | emit_move_insn (result, (gen_rtx_PLUS (SImode, tmp13, tmp10))); | |
2057 | } | |
2058 | ||
2059 | ||
2060 | /* Implement smulsi3_highpart. */ | |
2061 | void | |
2062 | tilepro_expand_smulsi3_highpart (rtx op0, rtx op1, rtx op2) | |
2063 | { | |
2064 | tilepro_expand_high_multiply (op0, op1, op2, true); | |
2065 | } | |
2066 | ||
2067 | ||
2068 | /* Implement umulsi3_highpart. */ | |
2069 | void | |
2070 | tilepro_expand_umulsi3_highpart (rtx op0, rtx op1, rtx op2) | |
2071 | { | |
2072 | tilepro_expand_high_multiply (op0, op1, op2, false); | |
2073 | } | |
2074 | \f | |
2075 | ||
2076 | ||
2077 | /* Compare and branches */ | |
2078 | ||
2079 | /* Helper function to handle DImode for tilepro_emit_setcc_internal. */ | |
2080 | static bool | |
2081 | tilepro_emit_setcc_internal_di (rtx res, enum rtx_code code, rtx op0, rtx op1) | |
2082 | { | |
2083 | rtx operands[2], lo_half[2], hi_half[2]; | |
2084 | rtx tmp, tmp0, tmp1, tmp2; | |
2085 | bool swap = false; | |
2086 | ||
2087 | /* Reduce the number of cases we need to handle by reversing the | |
2088 | operands. */ | |
2089 | switch (code) | |
2090 | { | |
2091 | case EQ: | |
2092 | case NE: | |
2093 | case LE: | |
2094 | case LT: | |
2095 | case LEU: | |
2096 | case LTU: | |
2097 | /* We handle these compares directly. */ | |
2098 | break; | |
2099 | ||
2100 | case GE: | |
2101 | case GT: | |
2102 | case GEU: | |
2103 | case GTU: | |
2104 | /* Reverse the operands. */ | |
2105 | swap = true; | |
2106 | break; | |
2107 | ||
2108 | default: | |
2109 | /* We should not have called this with any other code. */ | |
2110 | gcc_unreachable (); | |
2111 | } | |
2112 | ||
2113 | if (swap) | |
2114 | { | |
2115 | code = swap_condition (code); | |
2116 | tmp = op0, op0 = op1, op1 = tmp; | |
2117 | } | |
2118 | ||
2119 | operands[0] = op0; | |
2120 | operands[1] = op1; | |
2121 | ||
2122 | split_di (operands, 2, lo_half, hi_half); | |
2123 | ||
2124 | if (!reg_or_0_operand (lo_half[0], SImode)) | |
2125 | lo_half[0] = force_reg (SImode, lo_half[0]); | |
2126 | ||
2127 | if (!reg_or_0_operand (hi_half[0], SImode)) | |
2128 | hi_half[0] = force_reg (SImode, hi_half[0]); | |
2129 | ||
2130 | if (!CONST_INT_P (lo_half[1]) && !register_operand (lo_half[1], SImode)) | |
2131 | lo_half[1] = force_reg (SImode, lo_half[1]); | |
2132 | ||
2133 | if (!CONST_INT_P (hi_half[1]) && !register_operand (hi_half[1], SImode)) | |
2134 | hi_half[1] = force_reg (SImode, hi_half[1]); | |
2135 | ||
2136 | tmp0 = gen_reg_rtx (SImode); | |
2137 | tmp1 = gen_reg_rtx (SImode); | |
2138 | tmp2 = gen_reg_rtx (SImode); | |
2139 | ||
2140 | switch (code) | |
2141 | { | |
2142 | case EQ: | |
2143 | emit_insn (gen_insn_seq (tmp0, lo_half[0], lo_half[1])); | |
2144 | emit_insn (gen_insn_seq (tmp1, hi_half[0], hi_half[1])); | |
2145 | emit_insn (gen_andsi3 (res, tmp0, tmp1)); | |
2146 | return true; | |
2147 | break; | |
2148 | case NE: | |
2149 | emit_insn (gen_insn_sne (tmp0, lo_half[0], lo_half[1])); | |
2150 | emit_insn (gen_insn_sne (tmp1, hi_half[0], hi_half[1])); | |
2151 | emit_insn (gen_iorsi3 (res, tmp0, tmp1)); | |
2152 | return true; | |
2153 | break; | |
2154 | case LE: | |
2155 | emit_insn (gen_insn_slte (tmp0, hi_half[0], hi_half[1])); | |
2156 | emit_insn (gen_insn_seq (tmp1, hi_half[0], hi_half[1])); | |
2157 | emit_insn (gen_insn_slte_u (tmp2, lo_half[0], lo_half[1])); | |
2158 | emit_insn (gen_insn_mvnz (res, tmp0, tmp1, tmp2)); | |
2159 | return true; | |
2160 | case LT: | |
2161 | if (operands[1] == const0_rtx) | |
2162 | { | |
2163 | emit_insn (gen_lshrsi3 (res, hi_half[0], GEN_INT (31))); | |
2164 | return true; | |
2165 | } | |
2166 | else | |
2167 | { | |
2168 | emit_insn (gen_insn_slt (tmp0, hi_half[0], hi_half[1])); | |
2169 | emit_insn (gen_insn_seq (tmp1, hi_half[0], hi_half[1])); | |
2170 | emit_insn (gen_insn_slt_u (tmp2, lo_half[0], lo_half[1])); | |
2171 | emit_insn (gen_insn_mvnz (res, tmp0, tmp1, tmp2)); | |
2172 | } | |
2173 | return true; | |
2174 | case LEU: | |
2175 | emit_insn (gen_insn_slte_u (tmp0, hi_half[0], hi_half[1])); | |
2176 | emit_insn (gen_insn_seq (tmp1, hi_half[0], hi_half[1])); | |
2177 | emit_insn (gen_insn_slte_u (tmp2, lo_half[0], lo_half[1])); | |
2178 | emit_insn (gen_insn_mvnz (res, tmp0, tmp1, tmp2)); | |
2179 | return true; | |
2180 | case LTU: | |
2181 | emit_insn (gen_insn_slt_u (tmp0, hi_half[0], hi_half[1])); | |
2182 | emit_insn (gen_insn_seq (tmp1, hi_half[0], hi_half[1])); | |
2183 | emit_insn (gen_insn_slt_u (tmp2, lo_half[0], lo_half[1])); | |
2184 | emit_insn (gen_insn_mvnz (res, tmp0, tmp1, tmp2)); | |
2185 | return true; | |
2186 | default: | |
2187 | gcc_unreachable (); | |
2188 | } | |
2189 | ||
2190 | return false; | |
2191 | } | |
2192 | ||
2193 | ||
2194 | /* Certain simplifications can be done to make invalid setcc | |
2195 | operations valid. Return the final comparison, or NULL if we can't | |
2196 | work. */ | |
2197 | static bool | |
2198 | tilepro_emit_setcc_internal (rtx res, enum rtx_code code, rtx op0, rtx op1, | |
2199 | enum machine_mode cmp_mode) | |
2200 | { | |
2201 | rtx tmp; | |
2202 | bool swap = false; | |
2203 | ||
2204 | if (cmp_mode == DImode) | |
2205 | { | |
2206 | return tilepro_emit_setcc_internal_di (res, code, op0, op1); | |
2207 | } | |
2208 | ||
2209 | /* The general case: fold the comparison code to the types of | |
2210 | compares that we have, choosing the branch as necessary. */ | |
2211 | ||
2212 | switch (code) | |
2213 | { | |
2214 | case EQ: | |
2215 | case NE: | |
2216 | case LE: | |
2217 | case LT: | |
2218 | case LEU: | |
2219 | case LTU: | |
2220 | /* We have these compares. */ | |
2221 | break; | |
2222 | ||
2223 | case GE: | |
2224 | case GT: | |
2225 | case GEU: | |
2226 | case GTU: | |
2227 | /* We do not have these compares, so we reverse the | |
2228 | operands. */ | |
2229 | swap = true; | |
2230 | break; | |
2231 | ||
2232 | default: | |
2233 | /* We should not have called this with any other code. */ | |
2234 | gcc_unreachable (); | |
2235 | } | |
2236 | ||
2237 | if (swap) | |
2238 | { | |
2239 | code = swap_condition (code); | |
2240 | tmp = op0, op0 = op1, op1 = tmp; | |
2241 | } | |
2242 | ||
2243 | if (!reg_or_0_operand (op0, SImode)) | |
2244 | op0 = force_reg (SImode, op0); | |
2245 | ||
2246 | if (!CONST_INT_P (op1) && !register_operand (op1, SImode)) | |
2247 | op1 = force_reg (SImode, op1); | |
2248 | ||
2249 | /* Return the setcc comparison. */ | |
2250 | emit_insn (gen_rtx_SET (VOIDmode, res, | |
2251 | gen_rtx_fmt_ee (code, SImode, op0, op1))); | |
2252 | ||
2253 | return true; | |
2254 | } | |
2255 | ||
2256 | ||
2257 | /* Implement cstore patterns. */ | |
2258 | bool | |
2259 | tilepro_emit_setcc (rtx operands[], enum machine_mode cmp_mode) | |
2260 | { | |
2261 | return | |
2262 | tilepro_emit_setcc_internal (operands[0], GET_CODE (operands[1]), | |
2263 | operands[2], operands[3], cmp_mode); | |
2264 | } | |
2265 | ||
2266 | ||
2267 | /* Return whether CODE is a signed comparison. */ | |
2268 | static bool | |
2269 | signed_compare_p (enum rtx_code code) | |
2270 | { | |
2271 | return (code == EQ || code == NE || code == LT || code == LE | |
2272 | || code == GT || code == GE); | |
2273 | } | |
2274 | ||
2275 | ||
2276 | /* Generate the comparison for an SImode conditional branch. */ | |
2277 | static rtx | |
2278 | tilepro_emit_cc_test (enum rtx_code code, rtx op0, rtx op1, | |
2279 | enum machine_mode cmp_mode, bool eq_ne_only) | |
2280 | { | |
2281 | enum rtx_code branch_code; | |
2282 | rtx temp; | |
2283 | ||
2284 | /* Check for a compare against zero using a comparison we can do | |
2285 | directly. */ | |
2286 | if (cmp_mode != DImode | |
2287 | && op1 == const0_rtx | |
2288 | && (code == EQ || code == NE | |
2289 | || (!eq_ne_only && signed_compare_p (code)))) | |
2290 | { | |
2291 | op0 = force_reg (SImode, op0); | |
2292 | return gen_rtx_fmt_ee (code, VOIDmode, op0, const0_rtx); | |
2293 | } | |
2294 | ||
2295 | /* The general case: fold the comparison code to the types of | |
2296 | compares that we have, choosing the branch as necessary. */ | |
2297 | switch (code) | |
2298 | { | |
2299 | case EQ: | |
2300 | case LE: | |
2301 | case LT: | |
2302 | case LEU: | |
2303 | case LTU: | |
2304 | /* We have these compares. */ | |
2305 | branch_code = NE; | |
2306 | break; | |
2307 | ||
2308 | case NE: | |
2309 | case GE: | |
2310 | case GT: | |
2311 | case GEU: | |
2312 | case GTU: | |
2313 | /* These must be reversed (except NE, but let's | |
2314 | canonicalize). */ | |
2315 | code = reverse_condition (code); | |
2316 | branch_code = EQ; | |
2317 | break; | |
2318 | ||
2319 | default: | |
2320 | gcc_unreachable (); | |
2321 | } | |
2322 | ||
2323 | if (cmp_mode != DImode | |
2324 | && CONST_INT_P (op1) && (!satisfies_constraint_I (op1) || code == LEU)) | |
2325 | { | |
2326 | HOST_WIDE_INT n = trunc_int_for_mode (INTVAL (op1), SImode); | |
2327 | ||
2328 | switch (code) | |
2329 | { | |
2330 | case EQ: | |
2331 | /* Subtract off the value we want to compare against and see | |
2332 | if we get zero. This is cheaper than creating a constant | |
2333 | in a register. Except that subtracting -128 is more | |
2334 | expensive than seqi to -128, so we leave that alone. */ | |
2335 | /* ??? Don't do this when comparing against symbols, | |
2336 | otherwise we'll reduce (&x == 0x1234) to (&x-0x1234 == | |
2337 | 0), which will be declared false out of hand (at least | |
2338 | for non-weak). */ | |
2339 | if (!(symbolic_operand (op0, VOIDmode) | |
2340 | || (REG_P (op0) && REG_POINTER (op0)))) | |
2341 | { | |
2342 | /* To compare against MIN_INT, we add MIN_INT and check | |
2343 | for 0. */ | |
2344 | HOST_WIDE_INT add; | |
2345 | if (n != -2147483647 - 1) | |
2346 | add = -n; | |
2347 | else | |
2348 | add = n; | |
2349 | ||
2350 | op0 = force_reg (SImode, op0); | |
2351 | temp = gen_reg_rtx (SImode); | |
2352 | emit_insn (gen_addsi3 (temp, op0, gen_int_si (add))); | |
2353 | return gen_rtx_fmt_ee (reverse_condition (branch_code), | |
2354 | VOIDmode, temp, const0_rtx); | |
2355 | } | |
2356 | break; | |
2357 | ||
2358 | case LEU: | |
2359 | if (n == -1) | |
2360 | break; | |
2361 | /* FALLTHRU */ | |
2362 | ||
2363 | case LTU: | |
2364 | /* Change ((unsigned)x < 0x1000) into !((unsigned)x >> 12), | |
2365 | etc. */ | |
2366 | { | |
2367 | int first = exact_log2 (code == LTU ? n : n + 1); | |
2368 | if (first != -1) | |
2369 | { | |
2370 | op0 = force_reg (SImode, op0); | |
2371 | temp = gen_reg_rtx (SImode); | |
2372 | emit_move_insn (temp, | |
2373 | gen_rtx_LSHIFTRT (SImode, op0, | |
2374 | gen_int_si (first))); | |
2375 | return gen_rtx_fmt_ee (reverse_condition (branch_code), | |
2376 | VOIDmode, temp, const0_rtx); | |
2377 | } | |
2378 | } | |
2379 | break; | |
2380 | ||
2381 | default: | |
2382 | break; | |
2383 | } | |
2384 | } | |
2385 | ||
2386 | /* Compute a flag saying whether we should branch. */ | |
2387 | temp = gen_reg_rtx (SImode); | |
2388 | tilepro_emit_setcc_internal (temp, code, op0, op1, cmp_mode); | |
2389 | ||
2390 | /* Return the branch comparison. */ | |
2391 | return gen_rtx_fmt_ee (branch_code, VOIDmode, temp, const0_rtx); | |
2392 | } | |
2393 | ||
2394 | ||
2395 | /* Generate the comparison for a conditional branch. */ | |
2396 | void | |
2397 | tilepro_emit_conditional_branch (rtx operands[], enum machine_mode cmp_mode) | |
2398 | { | |
2399 | rtx cmp_rtx = | |
2400 | tilepro_emit_cc_test (GET_CODE (operands[0]), operands[1], operands[2], | |
2401 | cmp_mode, false); | |
2402 | rtx branch_rtx = gen_rtx_SET (VOIDmode, pc_rtx, | |
2403 | gen_rtx_IF_THEN_ELSE (VOIDmode, cmp_rtx, | |
2404 | gen_rtx_LABEL_REF | |
2405 | (VOIDmode, | |
2406 | operands[3]), | |
2407 | pc_rtx)); | |
2408 | emit_jump_insn (branch_rtx); | |
2409 | } | |
2410 | ||
2411 | ||
2412 | /* Implement the movsicc pattern. */ | |
2413 | rtx | |
2414 | tilepro_emit_conditional_move (rtx cmp) | |
2415 | { | |
2416 | return | |
2417 | tilepro_emit_cc_test (GET_CODE (cmp), XEXP (cmp, 0), XEXP (cmp, 1), | |
2418 | GET_MODE (XEXP (cmp, 0)), true); | |
2419 | } | |
2420 | ||
2421 | ||
2422 | /* Return true if INSN is annotated with a REG_BR_PROB note that | |
2423 | indicates it's a branch that's predicted taken. */ | |
2424 | static bool | |
2425 | cbranch_predicted_p (rtx insn) | |
2426 | { | |
2427 | rtx x = find_reg_note (insn, REG_BR_PROB, 0); | |
2428 | ||
2429 | if (x) | |
2430 | { | |
9eb946de | 2431 | int pred_val = XINT (x, 0); |
7ce78e23 | 2432 | |
2433 | return pred_val >= REG_BR_PROB_BASE / 2; | |
2434 | } | |
2435 | ||
2436 | return false; | |
2437 | } | |
2438 | ||
2439 | ||
2440 | /* Output assembly code for a specific branch instruction, appending | |
2441 | the branch prediction flag to the opcode if appropriate. */ | |
2442 | static const char * | |
2443 | tilepro_output_simple_cbranch_with_opcode (rtx insn, const char *opcode, | |
2444 | int regop, bool netreg_p, | |
2445 | bool reverse_predicted) | |
2446 | { | |
2447 | static char buf[64]; | |
2448 | sprintf (buf, "%s%s\t%%%c%d, %%l0", opcode, | |
2449 | (cbranch_predicted_p (insn) ^ reverse_predicted) ? "t" : "", | |
2450 | netreg_p ? 'N' : 'r', regop); | |
2451 | return buf; | |
2452 | } | |
2453 | ||
2454 | ||
2455 | /* Output assembly code for a specific branch instruction, appending | |
2456 | the branch prediction flag to the opcode if appropriate. */ | |
2457 | const char * | |
2458 | tilepro_output_cbranch_with_opcode (rtx insn, rtx *operands, | |
2459 | const char *opcode, | |
2460 | const char *rev_opcode, | |
2461 | int regop, bool netreg_p) | |
2462 | { | |
2463 | const char *branch_if_false; | |
2464 | rtx taken, not_taken; | |
2465 | bool is_simple_branch; | |
2466 | ||
2467 | gcc_assert (LABEL_P (operands[0])); | |
2468 | ||
2469 | is_simple_branch = true; | |
2470 | if (INSN_ADDRESSES_SET_P ()) | |
2471 | { | |
2472 | int from_addr = INSN_ADDRESSES (INSN_UID (insn)); | |
2473 | int to_addr = INSN_ADDRESSES (INSN_UID (operands[0])); | |
2474 | int delta = to_addr - from_addr; | |
2475 | is_simple_branch = IN_RANGE (delta, -524288, 524280); | |
2476 | } | |
2477 | ||
2478 | if (is_simple_branch) | |
2479 | { | |
2480 | /* Just a simple conditional branch. */ | |
2481 | return | |
2482 | tilepro_output_simple_cbranch_with_opcode (insn, opcode, regop, | |
2483 | netreg_p, false); | |
2484 | } | |
2485 | ||
2486 | /* Generate a reversed branch around a direct jump. This fallback | |
2487 | does not use branch-likely instructions. */ | |
2488 | not_taken = gen_label_rtx (); | |
2489 | taken = operands[0]; | |
2490 | ||
2491 | /* Generate the reversed branch to NOT_TAKEN. */ | |
2492 | operands[0] = not_taken; | |
2493 | branch_if_false = | |
2494 | tilepro_output_simple_cbranch_with_opcode (insn, rev_opcode, regop, | |
2495 | netreg_p, true); | |
2496 | output_asm_insn (branch_if_false, operands); | |
2497 | ||
2498 | output_asm_insn ("j\t%l0", &taken); | |
2499 | ||
2500 | /* Output NOT_TAKEN. */ | |
2501 | targetm.asm_out.internal_label (asm_out_file, "L", | |
2502 | CODE_LABEL_NUMBER (not_taken)); | |
2503 | return ""; | |
2504 | } | |
2505 | ||
2506 | ||
2507 | /* Output assembly code for a conditional branch instruction. */ | |
2508 | const char * | |
2509 | tilepro_output_cbranch (rtx insn, rtx *operands, bool reversed) | |
2510 | { | |
2511 | enum rtx_code code = GET_CODE (operands[1]); | |
2512 | const char *opcode; | |
2513 | const char *rev_opcode; | |
2514 | ||
2515 | if (reversed) | |
2516 | code = reverse_condition (code); | |
2517 | ||
2518 | switch (code) | |
2519 | { | |
2520 | case NE: | |
2521 | opcode = "bnz"; | |
2522 | rev_opcode = "bz"; | |
2523 | break; | |
2524 | case EQ: | |
2525 | opcode = "bz"; | |
2526 | rev_opcode = "bnz"; | |
2527 | break; | |
2528 | case GE: | |
2529 | opcode = "bgez"; | |
2530 | rev_opcode = "blz"; | |
2531 | break; | |
2532 | case GT: | |
2533 | opcode = "bgz"; | |
2534 | rev_opcode = "blez"; | |
2535 | break; | |
2536 | case LE: | |
2537 | opcode = "blez"; | |
2538 | rev_opcode = "bgz"; | |
2539 | break; | |
2540 | case LT: | |
2541 | opcode = "blz"; | |
2542 | rev_opcode = "bgez"; | |
2543 | break; | |
2544 | default: | |
2545 | gcc_unreachable (); | |
2546 | } | |
2547 | ||
2548 | return | |
2549 | tilepro_output_cbranch_with_opcode (insn, operands, opcode, rev_opcode, | |
2550 | 2, false); | |
2551 | } | |
2552 | ||
2553 | ||
2554 | /* Implement the tablejump pattern. */ | |
2555 | void | |
2556 | tilepro_expand_tablejump (rtx op0, rtx op1) | |
2557 | { | |
2558 | if (flag_pic) | |
2559 | { | |
2560 | rtx table = gen_rtx_LABEL_REF (Pmode, op1); | |
2561 | rtx temp = gen_reg_rtx (Pmode); | |
2562 | rtx text_label_symbol = tilepro_text_label_symbol (); | |
2563 | rtx text_label_rtx = tilepro_text_label_rtx (); | |
2564 | ||
2565 | emit_insn (gen_addli_pcrel (temp, text_label_rtx, | |
2566 | table, text_label_symbol)); | |
2567 | emit_insn (gen_auli_pcrel (temp, temp, table, text_label_symbol)); | |
2568 | emit_move_insn (temp, | |
2569 | gen_rtx_PLUS (Pmode, | |
2570 | convert_to_mode (Pmode, op0, false), | |
2571 | temp)); | |
2572 | op0 = temp; | |
2573 | } | |
2574 | ||
2575 | emit_jump_insn (gen_tablejump_aux (op0, op1)); | |
2576 | } | |
2577 | ||
2578 | ||
2579 | /* Expand a builtin vector binary op, by calling gen function GEN with | |
2580 | operands in the proper modes. DEST is converted to DEST_MODE, and | |
2581 | src0 and src1 (if DO_SRC1 is true) is converted to SRC_MODE. */ | |
2582 | void | |
2583 | tilepro_expand_builtin_vector_binop (rtx (*gen) (rtx, rtx, rtx), | |
2584 | enum machine_mode dest_mode, | |
2585 | rtx dest, | |
2586 | enum machine_mode src_mode, | |
2587 | rtx src0, rtx src1, bool do_src1) | |
2588 | { | |
2589 | dest = gen_lowpart (dest_mode, dest); | |
2590 | ||
2591 | if (src0 == const0_rtx) | |
2592 | src0 = CONST0_RTX (src_mode); | |
2593 | else | |
2594 | src0 = gen_lowpart (src_mode, src0); | |
2595 | ||
2596 | if (do_src1) | |
2597 | { | |
2598 | if (src1 == const0_rtx) | |
2599 | src1 = CONST0_RTX (src_mode); | |
2600 | else | |
2601 | src1 = gen_lowpart (src_mode, src1); | |
2602 | } | |
2603 | ||
2604 | emit_insn ((*gen) (dest, src0, src1)); | |
2605 | } | |
2606 | \f | |
2607 | ||
2608 | ||
2609 | /* Intrinsics */ | |
2610 | ||
2611 | struct tile_builtin_info | |
2612 | { | |
2613 | enum insn_code icode; | |
2614 | tree fndecl; | |
2615 | }; | |
2616 | ||
2617 | static struct tile_builtin_info tilepro_builtin_info[TILEPRO_BUILTIN_max] = { | |
2618 | { CODE_FOR_addsi3, NULL }, /* add */ | |
2619 | { CODE_FOR_insn_addb, NULL }, /* addb */ | |
2620 | { CODE_FOR_insn_addbs_u, NULL }, /* addbs_u */ | |
2621 | { CODE_FOR_insn_addh, NULL }, /* addh */ | |
2622 | { CODE_FOR_insn_addhs, NULL }, /* addhs */ | |
2623 | { CODE_FOR_insn_addib, NULL }, /* addib */ | |
2624 | { CODE_FOR_insn_addih, NULL }, /* addih */ | |
2625 | { CODE_FOR_insn_addlis, NULL }, /* addlis */ | |
2626 | { CODE_FOR_ssaddsi3, NULL }, /* adds */ | |
2627 | { CODE_FOR_insn_adiffb_u, NULL }, /* adiffb_u */ | |
2628 | { CODE_FOR_insn_adiffh, NULL }, /* adiffh */ | |
2629 | { CODE_FOR_andsi3, NULL }, /* and */ | |
2630 | { CODE_FOR_insn_auli, NULL }, /* auli */ | |
2631 | { CODE_FOR_insn_avgb_u, NULL }, /* avgb_u */ | |
2632 | { CODE_FOR_insn_avgh, NULL }, /* avgh */ | |
2633 | { CODE_FOR_insn_bitx, NULL }, /* bitx */ | |
2634 | { CODE_FOR_bswapsi2, NULL }, /* bytex */ | |
2635 | { CODE_FOR_clzsi2, NULL }, /* clz */ | |
2636 | { CODE_FOR_insn_crc32_32, NULL }, /* crc32_32 */ | |
2637 | { CODE_FOR_insn_crc32_8, NULL }, /* crc32_8 */ | |
2638 | { CODE_FOR_ctzsi2, NULL }, /* ctz */ | |
2639 | { CODE_FOR_insn_drain, NULL }, /* drain */ | |
2640 | { CODE_FOR_insn_dtlbpr, NULL }, /* dtlbpr */ | |
2641 | { CODE_FOR_insn_dword_align, NULL }, /* dword_align */ | |
2642 | { CODE_FOR_insn_finv, NULL }, /* finv */ | |
2643 | { CODE_FOR_insn_flush, NULL }, /* flush */ | |
2644 | { CODE_FOR_insn_fnop, NULL }, /* fnop */ | |
2645 | { CODE_FOR_insn_icoh, NULL }, /* icoh */ | |
2646 | { CODE_FOR_insn_ill, NULL }, /* ill */ | |
2647 | { CODE_FOR_insn_info, NULL }, /* info */ | |
2648 | { CODE_FOR_insn_infol, NULL }, /* infol */ | |
2649 | { CODE_FOR_insn_inthb, NULL }, /* inthb */ | |
2650 | { CODE_FOR_insn_inthh, NULL }, /* inthh */ | |
2651 | { CODE_FOR_insn_intlb, NULL }, /* intlb */ | |
2652 | { CODE_FOR_insn_intlh, NULL }, /* intlh */ | |
2653 | { CODE_FOR_insn_inv, NULL }, /* inv */ | |
2654 | { CODE_FOR_insn_lb, NULL }, /* lb */ | |
2655 | { CODE_FOR_insn_lb_u, NULL }, /* lb_u */ | |
2656 | { CODE_FOR_insn_lh, NULL }, /* lh */ | |
2657 | { CODE_FOR_insn_lh_u, NULL }, /* lh_u */ | |
2658 | { CODE_FOR_insn_lnk, NULL }, /* lnk */ | |
2659 | { CODE_FOR_insn_lw, NULL }, /* lw */ | |
2660 | { CODE_FOR_insn_lw_na, NULL }, /* lw_na */ | |
2661 | { CODE_FOR_insn_lb_L2, NULL }, /* lb_L2 */ | |
2662 | { CODE_FOR_insn_lb_u_L2, NULL }, /* lb_u_L2 */ | |
2663 | { CODE_FOR_insn_lh_L2, NULL }, /* lh_L2 */ | |
2664 | { CODE_FOR_insn_lh_u_L2, NULL }, /* lh_u_L2 */ | |
2665 | { CODE_FOR_insn_lw_L2, NULL }, /* lw_L2 */ | |
2666 | { CODE_FOR_insn_lw_na_L2, NULL }, /* lw_na_L2 */ | |
2667 | { CODE_FOR_insn_lb_miss, NULL }, /* lb_miss */ | |
2668 | { CODE_FOR_insn_lb_u_miss, NULL }, /* lb_u_miss */ | |
2669 | { CODE_FOR_insn_lh_miss, NULL }, /* lh_miss */ | |
2670 | { CODE_FOR_insn_lh_u_miss, NULL }, /* lh_u_miss */ | |
2671 | { CODE_FOR_insn_lw_miss, NULL }, /* lw_miss */ | |
2672 | { CODE_FOR_insn_lw_na_miss, NULL }, /* lw_na_miss */ | |
2673 | { CODE_FOR_insn_maxb_u, NULL }, /* maxb_u */ | |
2674 | { CODE_FOR_insn_maxh, NULL }, /* maxh */ | |
2675 | { CODE_FOR_insn_maxib_u, NULL }, /* maxib_u */ | |
2676 | { CODE_FOR_insn_maxih, NULL }, /* maxih */ | |
2677 | { CODE_FOR_memory_barrier, NULL }, /* mf */ | |
2678 | { CODE_FOR_insn_mfspr, NULL }, /* mfspr */ | |
2679 | { CODE_FOR_insn_minb_u, NULL }, /* minb_u */ | |
2680 | { CODE_FOR_insn_minh, NULL }, /* minh */ | |
2681 | { CODE_FOR_insn_minib_u, NULL }, /* minib_u */ | |
2682 | { CODE_FOR_insn_minih, NULL }, /* minih */ | |
2683 | { CODE_FOR_insn_mm, NULL }, /* mm */ | |
2684 | { CODE_FOR_insn_mnz, NULL }, /* mnz */ | |
2685 | { CODE_FOR_insn_mnzb, NULL }, /* mnzb */ | |
2686 | { CODE_FOR_insn_mnzh, NULL }, /* mnzh */ | |
2687 | { CODE_FOR_movsi, NULL }, /* move */ | |
2688 | { CODE_FOR_insn_movelis, NULL }, /* movelis */ | |
2689 | { CODE_FOR_insn_mtspr, NULL }, /* mtspr */ | |
2690 | { CODE_FOR_insn_mulhh_ss, NULL }, /* mulhh_ss */ | |
2691 | { CODE_FOR_insn_mulhh_su, NULL }, /* mulhh_su */ | |
2692 | { CODE_FOR_insn_mulhh_uu, NULL }, /* mulhh_uu */ | |
2693 | { CODE_FOR_insn_mulhha_ss, NULL }, /* mulhha_ss */ | |
2694 | { CODE_FOR_insn_mulhha_su, NULL }, /* mulhha_su */ | |
2695 | { CODE_FOR_insn_mulhha_uu, NULL }, /* mulhha_uu */ | |
2696 | { CODE_FOR_insn_mulhhsa_uu, NULL }, /* mulhhsa_uu */ | |
2697 | { CODE_FOR_insn_mulhl_ss, NULL }, /* mulhl_ss */ | |
2698 | { CODE_FOR_insn_mulhl_su, NULL }, /* mulhl_su */ | |
2699 | { CODE_FOR_insn_mulhl_us, NULL }, /* mulhl_us */ | |
2700 | { CODE_FOR_insn_mulhl_uu, NULL }, /* mulhl_uu */ | |
2701 | { CODE_FOR_insn_mulhla_ss, NULL }, /* mulhla_ss */ | |
2702 | { CODE_FOR_insn_mulhla_su, NULL }, /* mulhla_su */ | |
2703 | { CODE_FOR_insn_mulhla_us, NULL }, /* mulhla_us */ | |
2704 | { CODE_FOR_insn_mulhla_uu, NULL }, /* mulhla_uu */ | |
2705 | { CODE_FOR_insn_mulhlsa_uu, NULL }, /* mulhlsa_uu */ | |
2706 | { CODE_FOR_insn_mulll_ss, NULL }, /* mulll_ss */ | |
2707 | { CODE_FOR_insn_mulll_su, NULL }, /* mulll_su */ | |
2708 | { CODE_FOR_insn_mulll_uu, NULL }, /* mulll_uu */ | |
2709 | { CODE_FOR_insn_mullla_ss, NULL }, /* mullla_ss */ | |
2710 | { CODE_FOR_insn_mullla_su, NULL }, /* mullla_su */ | |
2711 | { CODE_FOR_insn_mullla_uu, NULL }, /* mullla_uu */ | |
2712 | { CODE_FOR_insn_mulllsa_uu, NULL }, /* mulllsa_uu */ | |
2713 | { CODE_FOR_insn_mvnz, NULL }, /* mvnz */ | |
2714 | { CODE_FOR_insn_mvz, NULL }, /* mvz */ | |
2715 | { CODE_FOR_insn_mz, NULL }, /* mz */ | |
2716 | { CODE_FOR_insn_mzb, NULL }, /* mzb */ | |
2717 | { CODE_FOR_insn_mzh, NULL }, /* mzh */ | |
2718 | { CODE_FOR_insn_nap, NULL }, /* nap */ | |
2719 | { CODE_FOR_nop, NULL }, /* nop */ | |
2720 | { CODE_FOR_insn_nor, NULL }, /* nor */ | |
2721 | { CODE_FOR_iorsi3, NULL }, /* or */ | |
2722 | { CODE_FOR_insn_packbs_u, NULL }, /* packbs_u */ | |
2723 | { CODE_FOR_insn_packhb, NULL }, /* packhb */ | |
2724 | { CODE_FOR_insn_packhs, NULL }, /* packhs */ | |
2725 | { CODE_FOR_insn_packlb, NULL }, /* packlb */ | |
2726 | { CODE_FOR_popcountsi2, NULL }, /* pcnt */ | |
2727 | { CODE_FOR_insn_prefetch, NULL }, /* prefetch */ | |
2728 | { CODE_FOR_insn_prefetch_L1, NULL }, /* prefetch_L1 */ | |
2729 | { CODE_FOR_rotlsi3, NULL }, /* rl */ | |
2730 | { CODE_FOR_insn_s1a, NULL }, /* s1a */ | |
2731 | { CODE_FOR_insn_s2a, NULL }, /* s2a */ | |
2732 | { CODE_FOR_insn_s3a, NULL }, /* s3a */ | |
2733 | { CODE_FOR_insn_sadab_u, NULL }, /* sadab_u */ | |
2734 | { CODE_FOR_insn_sadah, NULL }, /* sadah */ | |
2735 | { CODE_FOR_insn_sadah_u, NULL }, /* sadah_u */ | |
2736 | { CODE_FOR_insn_sadb_u, NULL }, /* sadb_u */ | |
2737 | { CODE_FOR_insn_sadh, NULL }, /* sadh */ | |
2738 | { CODE_FOR_insn_sadh_u, NULL }, /* sadh_u */ | |
2739 | { CODE_FOR_insn_sb, NULL }, /* sb */ | |
2740 | { CODE_FOR_insn_seq, NULL }, /* seq */ | |
2741 | { CODE_FOR_insn_seqb, NULL }, /* seqb */ | |
2742 | { CODE_FOR_insn_seqh, NULL }, /* seqh */ | |
2743 | { CODE_FOR_insn_seqib, NULL }, /* seqib */ | |
2744 | { CODE_FOR_insn_seqih, NULL }, /* seqih */ | |
2745 | { CODE_FOR_insn_sh, NULL }, /* sh */ | |
2746 | { CODE_FOR_ashlsi3, NULL }, /* shl */ | |
2747 | { CODE_FOR_insn_shlb, NULL }, /* shlb */ | |
2748 | { CODE_FOR_insn_shlh, NULL }, /* shlh */ | |
2749 | { CODE_FOR_insn_shlb, NULL }, /* shlib */ | |
2750 | { CODE_FOR_insn_shlh, NULL }, /* shlih */ | |
2751 | { CODE_FOR_lshrsi3, NULL }, /* shr */ | |
2752 | { CODE_FOR_insn_shrb, NULL }, /* shrb */ | |
2753 | { CODE_FOR_insn_shrh, NULL }, /* shrh */ | |
2754 | { CODE_FOR_insn_shrb, NULL }, /* shrib */ | |
2755 | { CODE_FOR_insn_shrh, NULL }, /* shrih */ | |
2756 | { CODE_FOR_insn_slt, NULL }, /* slt */ | |
2757 | { CODE_FOR_insn_slt_u, NULL }, /* slt_u */ | |
2758 | { CODE_FOR_insn_sltb, NULL }, /* sltb */ | |
2759 | { CODE_FOR_insn_sltb_u, NULL }, /* sltb_u */ | |
2760 | { CODE_FOR_insn_slte, NULL }, /* slte */ | |
2761 | { CODE_FOR_insn_slte_u, NULL }, /* slte_u */ | |
2762 | { CODE_FOR_insn_slteb, NULL }, /* slteb */ | |
2763 | { CODE_FOR_insn_slteb_u, NULL }, /* slteb_u */ | |
2764 | { CODE_FOR_insn_slteh, NULL }, /* slteh */ | |
2765 | { CODE_FOR_insn_slteh_u, NULL }, /* slteh_u */ | |
2766 | { CODE_FOR_insn_slth, NULL }, /* slth */ | |
2767 | { CODE_FOR_insn_slth_u, NULL }, /* slth_u */ | |
2768 | { CODE_FOR_insn_sltib, NULL }, /* sltib */ | |
2769 | { CODE_FOR_insn_sltib_u, NULL }, /* sltib_u */ | |
2770 | { CODE_FOR_insn_sltih, NULL }, /* sltih */ | |
2771 | { CODE_FOR_insn_sltih_u, NULL }, /* sltih_u */ | |
2772 | { CODE_FOR_insn_sne, NULL }, /* sne */ | |
2773 | { CODE_FOR_insn_sneb, NULL }, /* sneb */ | |
2774 | { CODE_FOR_insn_sneh, NULL }, /* sneh */ | |
2775 | { CODE_FOR_ashrsi3, NULL }, /* sra */ | |
2776 | { CODE_FOR_insn_srab, NULL }, /* srab */ | |
2777 | { CODE_FOR_insn_srah, NULL }, /* srah */ | |
2778 | { CODE_FOR_insn_srab, NULL }, /* sraib */ | |
2779 | { CODE_FOR_insn_srah, NULL }, /* sraih */ | |
2780 | { CODE_FOR_subsi3, NULL }, /* sub */ | |
2781 | { CODE_FOR_insn_subb, NULL }, /* subb */ | |
2782 | { CODE_FOR_insn_subbs_u, NULL }, /* subbs_u */ | |
2783 | { CODE_FOR_insn_subh, NULL }, /* subh */ | |
2784 | { CODE_FOR_insn_subhs, NULL }, /* subhs */ | |
2785 | { CODE_FOR_sssubsi3, NULL }, /* subs */ | |
2786 | { CODE_FOR_insn_sw, NULL }, /* sw */ | |
2787 | { CODE_FOR_insn_tblidxb0, NULL }, /* tblidxb0 */ | |
2788 | { CODE_FOR_insn_tblidxb1, NULL }, /* tblidxb1 */ | |
2789 | { CODE_FOR_insn_tblidxb2, NULL }, /* tblidxb2 */ | |
2790 | { CODE_FOR_insn_tblidxb3, NULL }, /* tblidxb3 */ | |
2791 | { CODE_FOR_insn_tns, NULL }, /* tns */ | |
2792 | { CODE_FOR_insn_wh64, NULL }, /* wh64 */ | |
2793 | { CODE_FOR_xorsi3, NULL }, /* xor */ | |
2794 | { CODE_FOR_tilepro_network_barrier, NULL }, /* network_barrier */ | |
2795 | { CODE_FOR_tilepro_idn0_receive, NULL }, /* idn0_receive */ | |
2796 | { CODE_FOR_tilepro_idn1_receive, NULL }, /* idn1_receive */ | |
2797 | { CODE_FOR_tilepro_idn_send, NULL }, /* idn_send */ | |
2798 | { CODE_FOR_tilepro_sn_receive, NULL }, /* sn_receive */ | |
2799 | { CODE_FOR_tilepro_sn_send, NULL }, /* sn_send */ | |
2800 | { CODE_FOR_tilepro_udn0_receive, NULL }, /* udn0_receive */ | |
2801 | { CODE_FOR_tilepro_udn1_receive, NULL }, /* udn1_receive */ | |
2802 | { CODE_FOR_tilepro_udn2_receive, NULL }, /* udn2_receive */ | |
2803 | { CODE_FOR_tilepro_udn3_receive, NULL }, /* udn3_receive */ | |
2804 | { CODE_FOR_tilepro_udn_send, NULL }, /* udn_send */ | |
2805 | }; | |
2806 | ||
2807 | ||
2808 | struct tilepro_builtin_def | |
2809 | { | |
2810 | const char *name; | |
2811 | enum tilepro_builtin code; | |
2812 | bool is_const; | |
2813 | /* The first character is the return type. Subsequent characters | |
2814 | are the argument types. See char_to_type. */ | |
2815 | const char *type; | |
2816 | }; | |
2817 | ||
2818 | ||
2819 | static const struct tilepro_builtin_def tilepro_builtins[] = { | |
2820 | { "__insn_add", TILEPRO_INSN_ADD, true, "lll" }, | |
2821 | { "__insn_addb", TILEPRO_INSN_ADDB, true, "lll" }, | |
2822 | { "__insn_addbs_u", TILEPRO_INSN_ADDBS_U, false, "lll" }, | |
2823 | { "__insn_addh", TILEPRO_INSN_ADDH, true, "lll" }, | |
2824 | { "__insn_addhs", TILEPRO_INSN_ADDHS, false, "lll" }, | |
2825 | { "__insn_addi", TILEPRO_INSN_ADD, true, "lll" }, | |
2826 | { "__insn_addib", TILEPRO_INSN_ADDIB, true, "lll" }, | |
2827 | { "__insn_addih", TILEPRO_INSN_ADDIH, true, "lll" }, | |
2828 | { "__insn_addli", TILEPRO_INSN_ADD, true, "lll" }, | |
2829 | { "__insn_addlis", TILEPRO_INSN_ADDLIS, false, "lll" }, | |
2830 | { "__insn_adds", TILEPRO_INSN_ADDS, false, "lll" }, | |
2831 | { "__insn_adiffb_u", TILEPRO_INSN_ADIFFB_U, true, "lll" }, | |
2832 | { "__insn_adiffh", TILEPRO_INSN_ADIFFH, true, "lll" }, | |
2833 | { "__insn_and", TILEPRO_INSN_AND, true, "lll" }, | |
2834 | { "__insn_andi", TILEPRO_INSN_AND, true, "lll" }, | |
2835 | { "__insn_auli", TILEPRO_INSN_AULI, true, "lll" }, | |
2836 | { "__insn_avgb_u", TILEPRO_INSN_AVGB_U, true, "lll" }, | |
2837 | { "__insn_avgh", TILEPRO_INSN_AVGH, true, "lll" }, | |
2838 | { "__insn_bitx", TILEPRO_INSN_BITX, true, "ll" }, | |
2839 | { "__insn_bytex", TILEPRO_INSN_BYTEX, true, "ll" }, | |
2840 | { "__insn_clz", TILEPRO_INSN_CLZ, true, "ll" }, | |
2841 | { "__insn_crc32_32", TILEPRO_INSN_CRC32_32, true, "lll" }, | |
2842 | { "__insn_crc32_8", TILEPRO_INSN_CRC32_8, true, "lll" }, | |
2843 | { "__insn_ctz", TILEPRO_INSN_CTZ, true, "ll" }, | |
2844 | { "__insn_drain", TILEPRO_INSN_DRAIN, false, "v" }, | |
2845 | { "__insn_dtlbpr", TILEPRO_INSN_DTLBPR, false, "vl" }, | |
2846 | { "__insn_dword_align", TILEPRO_INSN_DWORD_ALIGN, true, "lllk" }, | |
2847 | { "__insn_finv", TILEPRO_INSN_FINV, false, "vk" }, | |
2848 | { "__insn_flush", TILEPRO_INSN_FLUSH, false, "vk" }, | |
2849 | { "__insn_fnop", TILEPRO_INSN_FNOP, false, "v" }, | |
2850 | { "__insn_icoh", TILEPRO_INSN_ICOH, false, "vk" }, | |
2851 | { "__insn_ill", TILEPRO_INSN_ILL, false, "v" }, | |
2852 | { "__insn_info", TILEPRO_INSN_INFO, false, "vl" }, | |
2853 | { "__insn_infol", TILEPRO_INSN_INFOL, false, "vl" }, | |
2854 | { "__insn_inthb", TILEPRO_INSN_INTHB, true, "lll" }, | |
2855 | { "__insn_inthh", TILEPRO_INSN_INTHH, true, "lll" }, | |
2856 | { "__insn_intlb", TILEPRO_INSN_INTLB, true, "lll" }, | |
2857 | { "__insn_intlh", TILEPRO_INSN_INTLH, true, "lll" }, | |
2858 | { "__insn_inv", TILEPRO_INSN_INV, false, "vp" }, | |
2859 | { "__insn_lb", TILEPRO_INSN_LB, false, "lk" }, | |
2860 | { "__insn_lb_u", TILEPRO_INSN_LB_U, false, "lk" }, | |
2861 | { "__insn_lh", TILEPRO_INSN_LH, false, "lk" }, | |
2862 | { "__insn_lh_u", TILEPRO_INSN_LH_U, false, "lk" }, | |
2863 | { "__insn_lnk", TILEPRO_INSN_LNK, true, "l" }, | |
2864 | { "__insn_lw", TILEPRO_INSN_LW, false, "lk" }, | |
2865 | { "__insn_lw_na", TILEPRO_INSN_LW_NA, false, "lk" }, | |
2866 | { "__insn_lb_L2", TILEPRO_INSN_LB_L2, false, "lk" }, | |
2867 | { "__insn_lb_u_L2", TILEPRO_INSN_LB_U_L2, false, "lk" }, | |
2868 | { "__insn_lh_L2", TILEPRO_INSN_LH_L2, false, "lk" }, | |
2869 | { "__insn_lh_u_L2", TILEPRO_INSN_LH_U_L2, false, "lk" }, | |
2870 | { "__insn_lw_L2", TILEPRO_INSN_LW_L2, false, "lk" }, | |
2871 | { "__insn_lw_na_L2", TILEPRO_INSN_LW_NA_L2, false, "lk" }, | |
2872 | { "__insn_lb_miss", TILEPRO_INSN_LB_MISS, false, "lk" }, | |
2873 | { "__insn_lb_u_miss", TILEPRO_INSN_LB_U_MISS, false, "lk" }, | |
2874 | { "__insn_lh_miss", TILEPRO_INSN_LH_MISS, false, "lk" }, | |
2875 | { "__insn_lh_u_miss", TILEPRO_INSN_LH_U_MISS, false, "lk" }, | |
2876 | { "__insn_lw_miss", TILEPRO_INSN_LW_MISS, false, "lk" }, | |
2877 | { "__insn_lw_na_miss", TILEPRO_INSN_LW_NA_MISS, false, "lk" }, | |
2878 | { "__insn_maxb_u", TILEPRO_INSN_MAXB_U, true, "lll" }, | |
2879 | { "__insn_maxh", TILEPRO_INSN_MAXH, true, "lll" }, | |
2880 | { "__insn_maxib_u", TILEPRO_INSN_MAXIB_U, true, "lll" }, | |
2881 | { "__insn_maxih", TILEPRO_INSN_MAXIH, true, "lll" }, | |
2882 | { "__insn_mf", TILEPRO_INSN_MF, false, "v" }, | |
2883 | { "__insn_mfspr", TILEPRO_INSN_MFSPR, false, "ll" }, | |
2884 | { "__insn_minb_u", TILEPRO_INSN_MINB_U, true, "lll" }, | |
2885 | { "__insn_minh", TILEPRO_INSN_MINH, true, "lll" }, | |
2886 | { "__insn_minib_u", TILEPRO_INSN_MINIB_U, true, "lll" }, | |
2887 | { "__insn_minih", TILEPRO_INSN_MINIH, true, "lll" }, | |
2888 | { "__insn_mm", TILEPRO_INSN_MM, true, "lllll" }, | |
2889 | { "__insn_mnz", TILEPRO_INSN_MNZ, true, "lll" }, | |
2890 | { "__insn_mnzb", TILEPRO_INSN_MNZB, true, "lll" }, | |
2891 | { "__insn_mnzh", TILEPRO_INSN_MNZH, true, "lll" }, | |
2892 | { "__insn_move", TILEPRO_INSN_MOVE, true, "ll" }, | |
2893 | { "__insn_movei", TILEPRO_INSN_MOVE, true, "ll" }, | |
2894 | { "__insn_moveli", TILEPRO_INSN_MOVE, true, "ll" }, | |
2895 | { "__insn_movelis", TILEPRO_INSN_MOVELIS, false, "ll" }, | |
2896 | { "__insn_mtspr", TILEPRO_INSN_MTSPR, false, "vll" }, | |
2897 | { "__insn_mulhh_ss", TILEPRO_INSN_MULHH_SS, true, "lll" }, | |
2898 | { "__insn_mulhh_su", TILEPRO_INSN_MULHH_SU, true, "lll" }, | |
2899 | { "__insn_mulhh_uu", TILEPRO_INSN_MULHH_UU, true, "lll" }, | |
2900 | { "__insn_mulhha_ss", TILEPRO_INSN_MULHHA_SS, true, "llll" }, | |
2901 | { "__insn_mulhha_su", TILEPRO_INSN_MULHHA_SU, true, "llll" }, | |
2902 | { "__insn_mulhha_uu", TILEPRO_INSN_MULHHA_UU, true, "llll" }, | |
2903 | { "__insn_mulhhsa_uu", TILEPRO_INSN_MULHHSA_UU, true, "llll" }, | |
2904 | { "__insn_mulhl_ss", TILEPRO_INSN_MULHL_SS, true, "lll" }, | |
2905 | { "__insn_mulhl_su", TILEPRO_INSN_MULHL_SU, true, "lll" }, | |
2906 | { "__insn_mulhl_us", TILEPRO_INSN_MULHL_US, true, "lll" }, | |
2907 | { "__insn_mulhl_uu", TILEPRO_INSN_MULHL_UU, true, "lll" }, | |
2908 | { "__insn_mulhla_ss", TILEPRO_INSN_MULHLA_SS, true, "llll" }, | |
2909 | { "__insn_mulhla_su", TILEPRO_INSN_MULHLA_SU, true, "llll" }, | |
2910 | { "__insn_mulhla_us", TILEPRO_INSN_MULHLA_US, true, "llll" }, | |
2911 | { "__insn_mulhla_uu", TILEPRO_INSN_MULHLA_UU, true, "llll" }, | |
2912 | { "__insn_mulhlsa_uu", TILEPRO_INSN_MULHLSA_UU, true, "llll" }, | |
2913 | { "__insn_mulll_ss", TILEPRO_INSN_MULLL_SS, true, "lll" }, | |
2914 | { "__insn_mulll_su", TILEPRO_INSN_MULLL_SU, true, "lll" }, | |
2915 | { "__insn_mulll_uu", TILEPRO_INSN_MULLL_UU, true, "lll" }, | |
2916 | { "__insn_mullla_ss", TILEPRO_INSN_MULLLA_SS, true, "llll" }, | |
2917 | { "__insn_mullla_su", TILEPRO_INSN_MULLLA_SU, true, "llll" }, | |
2918 | { "__insn_mullla_uu", TILEPRO_INSN_MULLLA_UU, true, "llll" }, | |
2919 | { "__insn_mulllsa_uu", TILEPRO_INSN_MULLLSA_UU, true, "llll" }, | |
2920 | { "__insn_mvnz", TILEPRO_INSN_MVNZ, true, "llll" }, | |
2921 | { "__insn_mvz", TILEPRO_INSN_MVZ, true, "llll" }, | |
2922 | { "__insn_mz", TILEPRO_INSN_MZ, true, "lll" }, | |
2923 | { "__insn_mzb", TILEPRO_INSN_MZB, true, "lll" }, | |
2924 | { "__insn_mzh", TILEPRO_INSN_MZH, true, "lll" }, | |
2925 | { "__insn_nap", TILEPRO_INSN_NAP, false, "v" }, | |
2926 | { "__insn_nop", TILEPRO_INSN_NOP, true, "v" }, | |
2927 | { "__insn_nor", TILEPRO_INSN_NOR, true, "lll" }, | |
2928 | { "__insn_or", TILEPRO_INSN_OR, true, "lll" }, | |
2929 | { "__insn_ori", TILEPRO_INSN_OR, true, "lll" }, | |
2930 | { "__insn_packbs_u", TILEPRO_INSN_PACKBS_U, false, "lll" }, | |
2931 | { "__insn_packhb", TILEPRO_INSN_PACKHB, true, "lll" }, | |
2932 | { "__insn_packhs", TILEPRO_INSN_PACKHS, false, "lll" }, | |
2933 | { "__insn_packlb", TILEPRO_INSN_PACKLB, true, "lll" }, | |
2934 | { "__insn_pcnt", TILEPRO_INSN_PCNT, true, "ll" }, | |
2935 | { "__insn_prefetch", TILEPRO_INSN_PREFETCH, false, "vk" }, | |
2936 | { "__insn_prefetch_L1", TILEPRO_INSN_PREFETCH_L1, false, "vk" }, | |
2937 | { "__insn_rl", TILEPRO_INSN_RL, true, "lll" }, | |
2938 | { "__insn_rli", TILEPRO_INSN_RL, true, "lll" }, | |
2939 | { "__insn_s1a", TILEPRO_INSN_S1A, true, "lll" }, | |
2940 | { "__insn_s2a", TILEPRO_INSN_S2A, true, "lll" }, | |
2941 | { "__insn_s3a", TILEPRO_INSN_S3A, true, "lll" }, | |
2942 | { "__insn_sadab_u", TILEPRO_INSN_SADAB_U, true, "llll" }, | |
2943 | { "__insn_sadah", TILEPRO_INSN_SADAH, true, "llll" }, | |
2944 | { "__insn_sadah_u", TILEPRO_INSN_SADAH_U, true, "llll" }, | |
2945 | { "__insn_sadb_u", TILEPRO_INSN_SADB_U, true, "lll" }, | |
2946 | { "__insn_sadh", TILEPRO_INSN_SADH, true, "lll" }, | |
2947 | { "__insn_sadh_u", TILEPRO_INSN_SADH_U, true, "lll" }, | |
2948 | { "__insn_sb", TILEPRO_INSN_SB, false, "vpl" }, | |
2949 | { "__insn_seq", TILEPRO_INSN_SEQ, true, "lll" }, | |
2950 | { "__insn_seqb", TILEPRO_INSN_SEQB, true, "lll" }, | |
2951 | { "__insn_seqh", TILEPRO_INSN_SEQH, true, "lll" }, | |
2952 | { "__insn_seqi", TILEPRO_INSN_SEQ, true, "lll" }, | |
2953 | { "__insn_seqib", TILEPRO_INSN_SEQIB, true, "lll" }, | |
2954 | { "__insn_seqih", TILEPRO_INSN_SEQIH, true, "lll" }, | |
2955 | { "__insn_sh", TILEPRO_INSN_SH, false, "vpl" }, | |
2956 | { "__insn_shl", TILEPRO_INSN_SHL, true, "lll" }, | |
2957 | { "__insn_shlb", TILEPRO_INSN_SHLB, true, "lll" }, | |
2958 | { "__insn_shlh", TILEPRO_INSN_SHLH, true, "lll" }, | |
2959 | { "__insn_shli", TILEPRO_INSN_SHL, true, "lll" }, | |
2960 | { "__insn_shlib", TILEPRO_INSN_SHLIB, true, "lll" }, | |
2961 | { "__insn_shlih", TILEPRO_INSN_SHLIH, true, "lll" }, | |
2962 | { "__insn_shr", TILEPRO_INSN_SHR, true, "lll" }, | |
2963 | { "__insn_shrb", TILEPRO_INSN_SHRB, true, "lll" }, | |
2964 | { "__insn_shrh", TILEPRO_INSN_SHRH, true, "lll" }, | |
2965 | { "__insn_shri", TILEPRO_INSN_SHR, true, "lll" }, | |
2966 | { "__insn_shrib", TILEPRO_INSN_SHRIB, true, "lll" }, | |
2967 | { "__insn_shrih", TILEPRO_INSN_SHRIH, true, "lll" }, | |
2968 | { "__insn_slt", TILEPRO_INSN_SLT, true, "lll" }, | |
2969 | { "__insn_slt_u", TILEPRO_INSN_SLT_U, true, "lll" }, | |
2970 | { "__insn_sltb", TILEPRO_INSN_SLTB, true, "lll" }, | |
2971 | { "__insn_sltb_u", TILEPRO_INSN_SLTB_U, true, "lll" }, | |
2972 | { "__insn_slte", TILEPRO_INSN_SLTE, true, "lll" }, | |
2973 | { "__insn_slte_u", TILEPRO_INSN_SLTE_U, true, "lll" }, | |
2974 | { "__insn_slteb", TILEPRO_INSN_SLTEB, true, "lll" }, | |
2975 | { "__insn_slteb_u", TILEPRO_INSN_SLTEB_U, true, "lll" }, | |
2976 | { "__insn_slteh", TILEPRO_INSN_SLTEH, true, "lll" }, | |
2977 | { "__insn_slteh_u", TILEPRO_INSN_SLTEH_U, true, "lll" }, | |
2978 | { "__insn_slth", TILEPRO_INSN_SLTH, true, "lll" }, | |
2979 | { "__insn_slth_u", TILEPRO_INSN_SLTH_U, true, "lll" }, | |
2980 | { "__insn_slti", TILEPRO_INSN_SLT, true, "lll" }, | |
2981 | { "__insn_slti_u", TILEPRO_INSN_SLT_U, true, "lll" }, | |
2982 | { "__insn_sltib", TILEPRO_INSN_SLTIB, true, "lll" }, | |
2983 | { "__insn_sltib_u", TILEPRO_INSN_SLTIB_U, true, "lll" }, | |
2984 | { "__insn_sltih", TILEPRO_INSN_SLTIH, true, "lll" }, | |
2985 | { "__insn_sltih_u", TILEPRO_INSN_SLTIH_U, true, "lll" }, | |
2986 | { "__insn_sne", TILEPRO_INSN_SNE, true, "lll" }, | |
2987 | { "__insn_sneb", TILEPRO_INSN_SNEB, true, "lll" }, | |
2988 | { "__insn_sneh", TILEPRO_INSN_SNEH, true, "lll" }, | |
2989 | { "__insn_sra", TILEPRO_INSN_SRA, true, "lll" }, | |
2990 | { "__insn_srab", TILEPRO_INSN_SRAB, true, "lll" }, | |
2991 | { "__insn_srah", TILEPRO_INSN_SRAH, true, "lll" }, | |
2992 | { "__insn_srai", TILEPRO_INSN_SRA, true, "lll" }, | |
2993 | { "__insn_sraib", TILEPRO_INSN_SRAIB, true, "lll" }, | |
2994 | { "__insn_sraih", TILEPRO_INSN_SRAIH, true, "lll" }, | |
2995 | { "__insn_sub", TILEPRO_INSN_SUB, true, "lll" }, | |
2996 | { "__insn_subb", TILEPRO_INSN_SUBB, true, "lll" }, | |
2997 | { "__insn_subbs_u", TILEPRO_INSN_SUBBS_U, false, "lll" }, | |
2998 | { "__insn_subh", TILEPRO_INSN_SUBH, true, "lll" }, | |
2999 | { "__insn_subhs", TILEPRO_INSN_SUBHS, false, "lll" }, | |
3000 | { "__insn_subs", TILEPRO_INSN_SUBS, false, "lll" }, | |
3001 | { "__insn_sw", TILEPRO_INSN_SW, false, "vpl" }, | |
3002 | { "__insn_tblidxb0", TILEPRO_INSN_TBLIDXB0, true, "lll" }, | |
3003 | { "__insn_tblidxb1", TILEPRO_INSN_TBLIDXB1, true, "lll" }, | |
3004 | { "__insn_tblidxb2", TILEPRO_INSN_TBLIDXB2, true, "lll" }, | |
3005 | { "__insn_tblidxb3", TILEPRO_INSN_TBLIDXB3, true, "lll" }, | |
3006 | { "__insn_tns", TILEPRO_INSN_TNS, false, "lp" }, | |
3007 | { "__insn_wh64", TILEPRO_INSN_WH64, false, "vp" }, | |
3008 | { "__insn_xor", TILEPRO_INSN_XOR, true, "lll" }, | |
3009 | { "__insn_xori", TILEPRO_INSN_XOR, true, "lll" }, | |
3010 | { "__tile_network_barrier", TILEPRO_NETWORK_BARRIER, false, "v" }, | |
3011 | { "__tile_idn0_receive", TILEPRO_IDN0_RECEIVE, false, "l" }, | |
3012 | { "__tile_idn1_receive", TILEPRO_IDN1_RECEIVE, false, "l" }, | |
3013 | { "__tile_idn_send", TILEPRO_IDN_SEND, false, "vl" }, | |
3014 | { "__tile_sn_receive", TILEPRO_SN_RECEIVE, false, "l" }, | |
3015 | { "__tile_sn_send", TILEPRO_SN_SEND, false, "vl" }, | |
3016 | { "__tile_udn0_receive", TILEPRO_UDN0_RECEIVE, false, "l" }, | |
3017 | { "__tile_udn1_receive", TILEPRO_UDN1_RECEIVE, false, "l" }, | |
3018 | { "__tile_udn2_receive", TILEPRO_UDN2_RECEIVE, false, "l" }, | |
3019 | { "__tile_udn3_receive", TILEPRO_UDN3_RECEIVE, false, "l" }, | |
3020 | { "__tile_udn_send", TILEPRO_UDN_SEND, false, "vl" }, | |
3021 | }; | |
3022 | ||
3023 | ||
3024 | /* Convert a character in a builtin type string to a tree type. */ | |
3025 | static tree | |
3026 | char_to_type (char c) | |
3027 | { | |
3028 | static tree volatile_ptr_type_node = NULL; | |
3029 | static tree volatile_const_ptr_type_node = NULL; | |
3030 | ||
3031 | if (volatile_ptr_type_node == NULL) | |
3032 | { | |
3033 | volatile_ptr_type_node = | |
3034 | build_pointer_type (build_qualified_type (void_type_node, | |
3035 | TYPE_QUAL_VOLATILE)); | |
3036 | volatile_const_ptr_type_node = | |
3037 | build_pointer_type (build_qualified_type (void_type_node, | |
3038 | TYPE_QUAL_CONST | |
3039 | | TYPE_QUAL_VOLATILE)); | |
3040 | } | |
3041 | ||
3042 | switch (c) | |
3043 | { | |
3044 | case 'v': | |
3045 | return void_type_node; | |
3046 | case 'l': | |
3047 | return long_unsigned_type_node; | |
3048 | case 'p': | |
3049 | return volatile_ptr_type_node; | |
3050 | case 'k': | |
3051 | return volatile_const_ptr_type_node; | |
3052 | default: | |
3053 | gcc_unreachable (); | |
3054 | } | |
3055 | } | |
3056 | ||
3057 | ||
3058 | /* Implement TARGET_INIT_BUILTINS. */ | |
3059 | static void | |
3060 | tilepro_init_builtins (void) | |
3061 | { | |
3062 | size_t i; | |
3063 | ||
3064 | for (i = 0; i < ARRAY_SIZE (tilepro_builtins); i++) | |
3065 | { | |
3066 | const struct tilepro_builtin_def *p = &tilepro_builtins[i]; | |
3067 | tree ftype, ret_type, arg_type_list = void_list_node; | |
3068 | tree decl; | |
3069 | int j; | |
3070 | ||
3071 | for (j = strlen (p->type) - 1; j > 0; j--) | |
3072 | { | |
3073 | arg_type_list = | |
3074 | tree_cons (NULL_TREE, char_to_type (p->type[j]), arg_type_list); | |
3075 | } | |
3076 | ||
3077 | ret_type = char_to_type (p->type[0]); | |
3078 | ||
3079 | ftype = build_function_type (ret_type, arg_type_list); | |
3080 | ||
3081 | decl = add_builtin_function (p->name, ftype, p->code, BUILT_IN_MD, | |
3082 | NULL, NULL); | |
3083 | ||
3084 | if (p->is_const) | |
3085 | TREE_READONLY (decl) = 1; | |
3086 | TREE_NOTHROW (decl) = 1; | |
3087 | ||
3088 | if (tilepro_builtin_info[p->code].fndecl == NULL) | |
3089 | tilepro_builtin_info[p->code].fndecl = decl; | |
3090 | } | |
3091 | } | |
3092 | ||
3093 | ||
3094 | /* Implement TARGET_EXPAND_BUILTIN. */ | |
3095 | static rtx | |
3096 | tilepro_expand_builtin (tree exp, | |
3097 | rtx target, | |
3098 | rtx subtarget ATTRIBUTE_UNUSED, | |
3099 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
3100 | int ignore ATTRIBUTE_UNUSED) | |
3101 | { | |
3102 | #define MAX_BUILTIN_ARGS 4 | |
3103 | ||
3104 | tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0); | |
3105 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
3106 | tree arg; | |
3107 | call_expr_arg_iterator iter; | |
3108 | enum insn_code icode; | |
3109 | rtx op[MAX_BUILTIN_ARGS + 1], pat; | |
3110 | int opnum; | |
3111 | bool nonvoid; | |
3112 | insn_gen_fn fn; | |
3113 | ||
3114 | if (fcode >= TILEPRO_BUILTIN_max) | |
3115 | internal_error ("bad builtin fcode"); | |
3116 | icode = tilepro_builtin_info[fcode].icode; | |
3117 | if (icode == 0) | |
3118 | internal_error ("bad builtin icode"); | |
3119 | ||
3120 | nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node; | |
3121 | ||
3122 | opnum = nonvoid; | |
3123 | FOR_EACH_CALL_EXPR_ARG (arg, iter, exp) | |
3124 | { | |
3125 | const struct insn_operand_data *insn_op; | |
3126 | ||
3127 | if (arg == error_mark_node) | |
3128 | return NULL_RTX; | |
3129 | if (opnum > MAX_BUILTIN_ARGS) | |
3130 | return NULL_RTX; | |
3131 | ||
3132 | insn_op = &insn_data[icode].operand[opnum]; | |
3133 | ||
3134 | op[opnum] = expand_expr (arg, NULL_RTX, insn_op->mode, EXPAND_NORMAL); | |
3135 | ||
3136 | if (!(*insn_op->predicate) (op[opnum], insn_op->mode)) | |
3137 | op[opnum] = copy_to_mode_reg (insn_op->mode, op[opnum]); | |
3138 | ||
3139 | if (!(*insn_op->predicate) (op[opnum], insn_op->mode)) | |
3140 | { | |
3141 | /* We still failed to meet the predicate even after moving | |
3142 | into a register. Assume we needed an immediate. */ | |
3143 | error_at (EXPR_LOCATION (exp), | |
3144 | "operand must be an immediate of the right size"); | |
3145 | return const0_rtx; | |
3146 | } | |
3147 | ||
3148 | opnum++; | |
3149 | } | |
3150 | ||
3151 | if (nonvoid) | |
3152 | { | |
3153 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
3154 | if (!target | |
3155 | || GET_MODE (target) != tmode | |
3156 | || !(*insn_data[icode].operand[0].predicate) (target, tmode)) | |
3157 | target = gen_reg_rtx (tmode); | |
3158 | op[0] = target; | |
3159 | } | |
3160 | ||
3161 | fn = GEN_FCN (icode); | |
3162 | switch (opnum) | |
3163 | { | |
3164 | case 0: | |
3165 | pat = fn (NULL_RTX); | |
3166 | break; | |
3167 | case 1: | |
3168 | pat = fn (op[0]); | |
3169 | break; | |
3170 | case 2: | |
3171 | pat = fn (op[0], op[1]); | |
3172 | break; | |
3173 | case 3: | |
3174 | pat = fn (op[0], op[1], op[2]); | |
3175 | break; | |
3176 | case 4: | |
3177 | pat = fn (op[0], op[1], op[2], op[3]); | |
3178 | break; | |
3179 | case 5: | |
3180 | pat = fn (op[0], op[1], op[2], op[3], op[4]); | |
3181 | break; | |
3182 | default: | |
3183 | gcc_unreachable (); | |
3184 | } | |
3185 | if (!pat) | |
3186 | return NULL_RTX; | |
cfbf78c0 | 3187 | |
3188 | /* If we are generating a prefetch, tell the scheduler not to move | |
3189 | it around. */ | |
3190 | if (GET_CODE (pat) == PREFETCH) | |
3191 | PREFETCH_SCHEDULE_BARRIER_P (pat) = true; | |
3192 | ||
7ce78e23 | 3193 | emit_insn (pat); |
3194 | ||
3195 | if (nonvoid) | |
3196 | return target; | |
3197 | else | |
3198 | return const0_rtx; | |
3199 | } | |
3200 | ||
3201 | ||
3202 | /* Implement TARGET_BUILTIN_DECL. */ | |
3203 | static tree | |
3204 | tilepro_builtin_decl (unsigned code, bool initialize_p ATTRIBUTE_UNUSED) | |
3205 | { | |
3206 | if (code >= TILEPRO_BUILTIN_max) | |
3207 | return error_mark_node; | |
3208 | ||
3209 | return tilepro_builtin_info[code].fndecl; | |
3210 | } | |
3211 | \f | |
3212 | ||
3213 | ||
3214 | /* Stack frames */ | |
3215 | ||
3216 | /* Return whether REGNO needs to be saved in the stack frame. */ | |
3217 | static bool | |
3218 | need_to_save_reg (unsigned int regno) | |
3219 | { | |
3220 | if (!fixed_regs[regno] && !call_used_regs[regno] | |
3221 | && df_regs_ever_live_p (regno)) | |
3222 | return true; | |
3223 | ||
3224 | if (flag_pic | |
3225 | && (regno == PIC_OFFSET_TABLE_REGNUM | |
3226 | || regno == TILEPRO_PIC_TEXT_LABEL_REGNUM) | |
3227 | && (crtl->uses_pic_offset_table || crtl->saves_all_registers)) | |
3228 | return true; | |
3229 | ||
3230 | if (crtl->calls_eh_return) | |
3231 | { | |
3232 | unsigned i; | |
3233 | for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; i++) | |
3234 | { | |
3235 | if (regno == EH_RETURN_DATA_REGNO (i)) | |
3236 | return true; | |
3237 | } | |
3238 | } | |
3239 | ||
3240 | return false; | |
3241 | } | |
3242 | ||
3243 | ||
3244 | /* Return the size of the register savev area. This function is only | |
3245 | correct starting with local register allocation */ | |
3246 | static int | |
3247 | tilepro_saved_regs_size (void) | |
3248 | { | |
3249 | int reg_save_size = 0; | |
3250 | int regno; | |
3251 | int offset_to_frame; | |
3252 | int align_mask; | |
3253 | ||
3254 | for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) | |
3255 | if (need_to_save_reg (regno)) | |
3256 | reg_save_size += UNITS_PER_WORD; | |
3257 | ||
3258 | /* Pad out the register save area if necessary to make | |
3259 | frame_pointer_rtx be as aligned as the stack pointer. */ | |
3260 | offset_to_frame = crtl->args.pretend_args_size + reg_save_size; | |
3261 | align_mask = (STACK_BOUNDARY / BITS_PER_UNIT) - 1; | |
3262 | reg_save_size += (-offset_to_frame) & align_mask; | |
3263 | ||
3264 | return reg_save_size; | |
3265 | } | |
3266 | ||
3267 | ||
3268 | /* Round up frame size SIZE. */ | |
3269 | static int | |
3270 | round_frame_size (int size) | |
3271 | { | |
3272 | return ((size + STACK_BOUNDARY / BITS_PER_UNIT - 1) | |
3273 | & -STACK_BOUNDARY / BITS_PER_UNIT); | |
3274 | } | |
3275 | ||
3276 | ||
3277 | /* Emit a store in the stack frame to save REGNO at address ADDR, and | |
3278 | emit the corresponding REG_CFA_OFFSET note described by CFA and | |
3279 | CFA_OFFSET. Return the emitted insn. */ | |
3280 | static rtx | |
3281 | frame_emit_store (int regno, int regno_note, rtx addr, rtx cfa, | |
3282 | int cfa_offset) | |
3283 | { | |
3284 | rtx reg = gen_rtx_REG (Pmode, regno); | |
3285 | rtx mem = gen_frame_mem (Pmode, addr); | |
3286 | rtx mov = gen_movsi (mem, reg); | |
3287 | ||
3288 | /* Describe what just happened in a way that dwarf understands. We | |
3289 | use temporary registers to hold the address to make scheduling | |
3290 | easier, and use the REG_CFA_OFFSET to describe the address as an | |
3291 | offset from the CFA. */ | |
3292 | rtx reg_note = gen_rtx_REG (Pmode, regno_note); | |
3293 | rtx cfa_relative_addr = gen_rtx_PLUS (Pmode, cfa, gen_int_si (cfa_offset)); | |
3294 | rtx cfa_relative_mem = gen_frame_mem (Pmode, cfa_relative_addr); | |
3295 | rtx real = gen_rtx_SET (VOIDmode, cfa_relative_mem, reg_note); | |
3296 | add_reg_note (mov, REG_CFA_OFFSET, real); | |
3297 | ||
3298 | return emit_insn (mov); | |
3299 | } | |
3300 | ||
3301 | ||
3302 | /* Emit a load in the stack frame to load REGNO from address ADDR. | |
3303 | Add a REG_CFA_RESTORE note to CFA_RESTORES if CFA_RESTORES is | |
3304 | non-null. Return the emitted insn. */ | |
3305 | static rtx | |
3306 | frame_emit_load (int regno, rtx addr, rtx *cfa_restores) | |
3307 | { | |
3308 | rtx reg = gen_rtx_REG (Pmode, regno); | |
3309 | rtx mem = gen_frame_mem (Pmode, addr); | |
3310 | if (cfa_restores) | |
3311 | *cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg, *cfa_restores); | |
3312 | return emit_insn (gen_movsi (reg, mem)); | |
3313 | } | |
3314 | ||
3315 | ||
3316 | /* Helper function to set RTX_FRAME_RELATED_P on instructions, | |
3317 | including sequences. */ | |
3318 | static rtx | |
3319 | set_frame_related_p (void) | |
3320 | { | |
3321 | rtx seq = get_insns (); | |
3322 | rtx insn; | |
3323 | ||
3324 | end_sequence (); | |
3325 | ||
3326 | if (!seq) | |
3327 | return NULL_RTX; | |
3328 | ||
3329 | if (INSN_P (seq)) | |
3330 | { | |
3331 | insn = seq; | |
3332 | while (insn != NULL_RTX) | |
3333 | { | |
3334 | RTX_FRAME_RELATED_P (insn) = 1; | |
3335 | insn = NEXT_INSN (insn); | |
3336 | } | |
3337 | seq = emit_insn (seq); | |
3338 | } | |
3339 | else | |
3340 | { | |
3341 | seq = emit_insn (seq); | |
3342 | RTX_FRAME_RELATED_P (seq) = 1; | |
3343 | } | |
3344 | return seq; | |
3345 | } | |
3346 | ||
3347 | ||
3348 | #define FRP(exp) (start_sequence (), exp, set_frame_related_p ()) | |
3349 | ||
3350 | /* This emits code for 'sp += offset'. | |
3351 | ||
3352 | The ABI only allows us to modify 'sp' in a single 'addi' or | |
3353 | 'addli', so the backtracer understands it. Larger amounts cannot | |
3354 | use those instructions, so are added by placing the offset into a | |
3355 | large register and using 'add'. | |
3356 | ||
3357 | This happens after reload, so we need to expand it ourselves. */ | |
3358 | static rtx | |
3359 | emit_sp_adjust (int offset, int *next_scratch_regno, bool frame_related, | |
3360 | rtx reg_notes) | |
3361 | { | |
3362 | rtx to_add; | |
3363 | rtx imm_rtx = gen_int_si (offset); | |
3364 | ||
3365 | rtx insn; | |
3366 | if (satisfies_constraint_J (imm_rtx)) | |
3367 | { | |
3368 | /* We can add this using a single addi or addli. */ | |
3369 | to_add = imm_rtx; | |
3370 | } | |
3371 | else | |
3372 | { | |
3373 | rtx tmp = gen_rtx_REG (Pmode, (*next_scratch_regno)--); | |
3374 | tilepro_expand_set_const32 (tmp, imm_rtx); | |
3375 | to_add = tmp; | |
3376 | } | |
3377 | ||
3378 | /* Actually adjust the stack pointer. */ | |
3379 | insn = emit_insn (gen_sp_adjust (stack_pointer_rtx, stack_pointer_rtx, | |
3380 | to_add)); | |
3381 | REG_NOTES (insn) = reg_notes; | |
3382 | ||
3383 | /* Describe what just happened in a way that dwarf understands. */ | |
3384 | if (frame_related) | |
3385 | { | |
3386 | rtx real = gen_rtx_SET (VOIDmode, stack_pointer_rtx, | |
3387 | gen_rtx_PLUS (Pmode, stack_pointer_rtx, | |
3388 | imm_rtx)); | |
3389 | RTX_FRAME_RELATED_P (insn) = 1; | |
3390 | add_reg_note (insn, REG_CFA_ADJUST_CFA, real); | |
3391 | } | |
3392 | ||
3393 | return insn; | |
3394 | } | |
3395 | ||
3396 | ||
3397 | /* Return whether the current function is leaf. This takes into | |
3398 | account whether the function calls tls_get_addr. */ | |
3399 | static bool | |
3400 | tilepro_current_function_is_leaf (void) | |
3401 | { | |
d5bf7b64 | 3402 | return crtl->is_leaf && !cfun->machine->calls_tls_get_addr; |
7ce78e23 | 3403 | } |
3404 | ||
3405 | ||
3406 | /* Return the frame size. */ | |
3407 | static int | |
3408 | compute_total_frame_size (void) | |
3409 | { | |
3410 | int total_size = (get_frame_size () + tilepro_saved_regs_size () | |
3411 | + crtl->outgoing_args_size | |
3412 | + crtl->args.pretend_args_size); | |
3413 | ||
3414 | if (!tilepro_current_function_is_leaf () || cfun->calls_alloca) | |
3415 | { | |
3416 | /* Make room for save area in callee. */ | |
3417 | total_size += STACK_POINTER_OFFSET; | |
3418 | } | |
3419 | ||
3420 | return round_frame_size (total_size); | |
3421 | } | |
3422 | ||
3423 | ||
3424 | /* Return nonzero if this function is known to have a null epilogue. | |
3425 | This allows the optimizer to omit jumps to jumps if no stack was | |
3426 | created. */ | |
3427 | bool | |
3428 | tilepro_can_use_return_insn_p (void) | |
3429 | { | |
3430 | return (reload_completed | |
3431 | && cfun->static_chain_decl == 0 | |
3432 | && compute_total_frame_size () == 0 | |
3433 | && tilepro_current_function_is_leaf () | |
3434 | && !crtl->profile && !df_regs_ever_live_p (TILEPRO_LINK_REGNUM)); | |
3435 | } | |
3436 | ||
3437 | ||
3438 | /* Returns an rtx for a stack slot at 'FP + offset_from_fp'. If there | |
3439 | is a frame pointer, it computes the value relative to | |
3440 | that. Otherwise it uses the stack pointer. */ | |
3441 | static rtx | |
3442 | compute_frame_addr (int offset_from_fp, int *next_scratch_regno) | |
3443 | { | |
3444 | rtx base_reg_rtx, tmp_reg_rtx, offset_rtx; | |
3445 | int offset_from_base; | |
3446 | ||
3447 | if (frame_pointer_needed) | |
3448 | { | |
3449 | base_reg_rtx = hard_frame_pointer_rtx; | |
3450 | offset_from_base = offset_from_fp; | |
3451 | } | |
3452 | else | |
3453 | { | |
3454 | int offset_from_sp = compute_total_frame_size () + offset_from_fp; | |
3455 | base_reg_rtx = stack_pointer_rtx; | |
3456 | offset_from_base = offset_from_sp; | |
3457 | } | |
3458 | ||
3459 | if (offset_from_base == 0) | |
3460 | return base_reg_rtx; | |
3461 | ||
3462 | /* Compute the new value of the stack pointer. */ | |
3463 | tmp_reg_rtx = gen_rtx_REG (Pmode, (*next_scratch_regno)--); | |
3464 | offset_rtx = gen_int_si (offset_from_base); | |
3465 | ||
3466 | if (!tilepro_expand_addsi (tmp_reg_rtx, base_reg_rtx, offset_rtx)) | |
3467 | { | |
3468 | emit_insn (gen_rtx_SET (VOIDmode, tmp_reg_rtx, | |
3469 | gen_rtx_PLUS (Pmode, base_reg_rtx, | |
3470 | offset_rtx))); | |
3471 | } | |
3472 | ||
3473 | return tmp_reg_rtx; | |
3474 | } | |
3475 | ||
3476 | ||
3477 | /* The stack frame looks like this: | |
3478 | +-------------+ | |
3479 | | ... | | |
3480 | | incoming | | |
3481 | | stack args | | |
3482 | AP -> +-------------+ | |
3483 | | caller's HFP| | |
3484 | +-------------+ | |
3485 | | lr save | | |
3486 | HFP -> +-------------+ | |
3487 | | var args | | |
3488 | | reg save | crtl->args.pretend_args_size bytes | |
3489 | +-------------+ | |
3490 | | ... | | |
3491 | | saved regs | tilepro_saved_regs_size() bytes | |
3492 | FP -> +-------------+ | |
3493 | | ... | | |
3494 | | vars | get_frame_size() bytes | |
3495 | +-------------+ | |
3496 | | ... | | |
3497 | | outgoing | | |
3498 | | stack args | crtl->outgoing_args_size bytes | |
3499 | +-------------+ | |
3500 | | HFP | 4 bytes (only here if nonleaf / alloca) | |
3501 | +-------------+ | |
3502 | | callee lr | 4 bytes (only here if nonleaf / alloca) | |
3503 | | save | | |
3504 | SP -> +-------------+ | |
3505 | ||
3506 | HFP == incoming SP. | |
3507 | ||
3508 | For functions with a frame larger than 32767 bytes, or which use | |
3509 | alloca (), r52 is used as a frame pointer. Otherwise there is no | |
3510 | frame pointer. | |
3511 | ||
3512 | FP is saved at SP+4 before calling a subroutine so the | |
3513 | callee can chain. */ | |
3514 | void | |
3515 | tilepro_expand_prologue (void) | |
3516 | { | |
3517 | #define ROUND_ROBIN_SIZE 4 | |
3518 | /* We round-robin through four scratch registers to hold temporary | |
3519 | addresses for saving registers, to make instruction scheduling | |
3520 | easier. */ | |
3521 | rtx reg_save_addr[ROUND_ROBIN_SIZE] = { | |
3522 | NULL_RTX, NULL_RTX, NULL_RTX, NULL_RTX | |
3523 | }; | |
3524 | rtx insn, cfa; | |
3525 | unsigned int which_scratch; | |
3526 | int offset, start_offset, regno; | |
3527 | ||
3528 | /* A register that holds a copy of the incoming fp. */ | |
3529 | int fp_copy_regno = -1; | |
3530 | ||
3531 | /* A register that holds a copy of the incoming sp. */ | |
3532 | int sp_copy_regno = -1; | |
3533 | ||
3534 | /* Next scratch register number to hand out (postdecrementing). */ | |
3535 | int next_scratch_regno = 29; | |
3536 | ||
3537 | int total_size = compute_total_frame_size (); | |
3538 | ||
3539 | if (flag_stack_usage_info) | |
3540 | current_function_static_stack_size = total_size; | |
3541 | ||
3542 | /* Save lr first in its special location because code after this | |
3543 | might use the link register as a scratch register. */ | |
3544 | if (df_regs_ever_live_p (TILEPRO_LINK_REGNUM) || crtl->calls_eh_return) | |
3545 | FRP (frame_emit_store (TILEPRO_LINK_REGNUM, TILEPRO_LINK_REGNUM, | |
3546 | stack_pointer_rtx, stack_pointer_rtx, 0)); | |
3547 | ||
3548 | if (total_size == 0) | |
3549 | { | |
3550 | /* Load the PIC register if needed. */ | |
3551 | if (flag_pic && crtl->uses_pic_offset_table) | |
3552 | load_pic_register (false); | |
3553 | ||
3554 | return; | |
3555 | } | |
3556 | ||
3557 | cfa = stack_pointer_rtx; | |
3558 | ||
3559 | if (frame_pointer_needed) | |
3560 | { | |
3561 | fp_copy_regno = next_scratch_regno--; | |
3562 | ||
3563 | /* Copy the old frame pointer aside so we can save it later. */ | |
3564 | insn = FRP (emit_move_insn (gen_rtx_REG (word_mode, fp_copy_regno), | |
3565 | hard_frame_pointer_rtx)); | |
3566 | add_reg_note (insn, REG_CFA_REGISTER, NULL_RTX); | |
3567 | ||
3568 | /* Set up the frame pointer. */ | |
3569 | insn = FRP (emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx)); | |
3570 | add_reg_note (insn, REG_CFA_DEF_CFA, hard_frame_pointer_rtx); | |
3571 | cfa = hard_frame_pointer_rtx; | |
3572 | REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM) = STACK_BOUNDARY; | |
3573 | ||
3574 | /* fp holds a copy of the incoming sp, in case we need to store | |
3575 | it. */ | |
3576 | sp_copy_regno = HARD_FRAME_POINTER_REGNUM; | |
3577 | } | |
3578 | else if (!tilepro_current_function_is_leaf ()) | |
3579 | { | |
3580 | /* Copy the old stack pointer aside so we can save it later. */ | |
3581 | sp_copy_regno = next_scratch_regno--; | |
c6cfe48f | 3582 | emit_move_insn (gen_rtx_REG (Pmode, sp_copy_regno), |
3583 | stack_pointer_rtx); | |
7ce78e23 | 3584 | } |
3585 | ||
3586 | if (tilepro_current_function_is_leaf ()) | |
3587 | { | |
3588 | /* No need to store chain pointer to caller's frame. */ | |
3589 | emit_sp_adjust (-total_size, &next_scratch_regno, | |
3590 | !frame_pointer_needed, NULL_RTX); | |
3591 | } | |
3592 | else | |
3593 | { | |
3594 | /* Save the frame pointer (incoming sp value) to support | |
3595 | backtracing. First we need to create an rtx with the store | |
3596 | address. */ | |
3597 | rtx chain_addr = gen_rtx_REG (Pmode, next_scratch_regno--); | |
3598 | rtx size_rtx = gen_int_si (-(total_size - UNITS_PER_WORD)); | |
7ce78e23 | 3599 | |
3600 | if (add_operand (size_rtx, Pmode)) | |
3601 | { | |
3602 | /* Expose more parallelism by computing this value from the | |
3603 | original stack pointer, not the one after we have pushed | |
3604 | the frame. */ | |
3605 | rtx p = gen_rtx_PLUS (Pmode, stack_pointer_rtx, size_rtx); | |
3606 | emit_insn (gen_rtx_SET (VOIDmode, chain_addr, p)); | |
3607 | emit_sp_adjust (-total_size, &next_scratch_regno, | |
3608 | !frame_pointer_needed, NULL_RTX); | |
3609 | } | |
3610 | else | |
3611 | { | |
3612 | /* The stack frame is large, so just store the incoming sp | |
3613 | value at *(new_sp + UNITS_PER_WORD). */ | |
3614 | rtx p; | |
3615 | emit_sp_adjust (-total_size, &next_scratch_regno, | |
3616 | !frame_pointer_needed, NULL_RTX); | |
3617 | p = gen_rtx_PLUS (Pmode, stack_pointer_rtx, | |
3618 | GEN_INT (UNITS_PER_WORD)); | |
3619 | emit_insn (gen_rtx_SET (VOIDmode, chain_addr, p)); | |
3620 | } | |
3621 | ||
3622 | /* Save our frame pointer for backtrace chaining. */ | |
c6cfe48f | 3623 | emit_insn (gen_movsi (gen_frame_mem (SImode, chain_addr), |
3624 | gen_rtx_REG (SImode, sp_copy_regno))); | |
7ce78e23 | 3625 | } |
3626 | ||
3627 | /* Compute where to start storing registers we need to save. */ | |
3628 | start_offset = -crtl->args.pretend_args_size - UNITS_PER_WORD; | |
3629 | offset = start_offset; | |
3630 | ||
3631 | /* Store all registers that need saving. */ | |
3632 | which_scratch = 0; | |
3633 | for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--) | |
3634 | if (need_to_save_reg (regno)) | |
3635 | { | |
3636 | rtx r = reg_save_addr[which_scratch]; | |
3637 | int from_regno; | |
3638 | int cfa_offset = frame_pointer_needed ? offset : total_size + offset; | |
3639 | ||
3640 | if (r == NULL_RTX) | |
3641 | { | |
3642 | rtx p = compute_frame_addr (offset, &next_scratch_regno); | |
3643 | r = gen_rtx_REG (word_mode, next_scratch_regno--); | |
3644 | reg_save_addr[which_scratch] = r; | |
3645 | ||
3646 | emit_insn (gen_rtx_SET (VOIDmode, r, p)); | |
3647 | } | |
3648 | else | |
3649 | { | |
3650 | /* Advance to the next stack slot to store this register. */ | |
3651 | int stride = ROUND_ROBIN_SIZE * -UNITS_PER_WORD; | |
3652 | rtx p = gen_rtx_PLUS (Pmode, r, GEN_INT (stride)); | |
3653 | emit_insn (gen_rtx_SET (VOIDmode, r, p)); | |
3654 | } | |
3655 | ||
3656 | /* Save this register to the stack (but use the old fp value | |
3657 | we copied aside if appropriate). */ | |
3658 | from_regno = (fp_copy_regno >= 0 | |
3659 | && regno == | |
3660 | HARD_FRAME_POINTER_REGNUM) ? fp_copy_regno : regno; | |
3661 | FRP (frame_emit_store (from_regno, regno, r, cfa, cfa_offset)); | |
3662 | ||
3663 | offset -= UNITS_PER_WORD; | |
3664 | which_scratch = (which_scratch + 1) % ROUND_ROBIN_SIZE; | |
3665 | } | |
3666 | ||
3667 | /* If profiling, force that to happen after the frame is set up. */ | |
3668 | if (crtl->profile) | |
3669 | emit_insn (gen_blockage ()); | |
3670 | ||
3671 | /* Load the PIC register if needed. */ | |
3672 | if (flag_pic && crtl->uses_pic_offset_table) | |
3673 | load_pic_register (false); | |
3674 | } | |
3675 | ||
3676 | ||
3677 | /* Implement the epilogue and sibcall_epilogue patterns. SIBCALL_P is | |
3678 | true for a sibcall_epilogue pattern, and false for an epilogue | |
3679 | pattern. */ | |
3680 | void | |
3681 | tilepro_expand_epilogue (bool sibcall_p) | |
3682 | { | |
3683 | /* We round-robin through four scratch registers to hold temporary | |
3684 | addresses for saving registers, to make instruction scheduling | |
3685 | easier. */ | |
3686 | rtx reg_save_addr[ROUND_ROBIN_SIZE] = { | |
3687 | NULL_RTX, NULL_RTX, NULL_RTX, NULL_RTX | |
3688 | }; | |
3689 | rtx last_insn, insn; | |
3690 | unsigned int which_scratch; | |
3691 | int offset, start_offset, regno; | |
3692 | rtx cfa_restores = NULL_RTX; | |
3693 | ||
3694 | /* A register that holds a copy of the incoming fp. */ | |
3695 | int fp_copy_regno = -1; | |
3696 | ||
3697 | /* Next scratch register number to hand out (postdecrementing). */ | |
3698 | int next_scratch_regno = 29; | |
3699 | ||
3700 | int total_size = compute_total_frame_size (); | |
3701 | ||
3702 | last_insn = get_last_insn (); | |
3703 | ||
3704 | /* Load lr first since we are going to need it first. */ | |
3705 | insn = NULL; | |
3706 | if (df_regs_ever_live_p (TILEPRO_LINK_REGNUM)) | |
3707 | { | |
3708 | insn = frame_emit_load (TILEPRO_LINK_REGNUM, | |
3709 | compute_frame_addr (0, &next_scratch_regno), | |
3710 | &cfa_restores); | |
3711 | } | |
3712 | ||
3713 | if (total_size == 0) | |
3714 | { | |
3715 | if (insn) | |
3716 | { | |
3717 | RTX_FRAME_RELATED_P (insn) = 1; | |
3718 | REG_NOTES (insn) = cfa_restores; | |
3719 | } | |
3720 | goto done; | |
3721 | } | |
3722 | ||
3723 | /* Compute where to start restoring registers. */ | |
3724 | start_offset = -crtl->args.pretend_args_size - UNITS_PER_WORD; | |
3725 | offset = start_offset; | |
3726 | ||
3727 | if (frame_pointer_needed) | |
3728 | fp_copy_regno = next_scratch_regno--; | |
3729 | ||
3730 | /* Restore all callee-saved registers. */ | |
3731 | which_scratch = 0; | |
3732 | for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--) | |
3733 | if (need_to_save_reg (regno)) | |
3734 | { | |
3735 | rtx r = reg_save_addr[which_scratch]; | |
3736 | if (r == NULL_RTX) | |
3737 | { | |
3738 | r = compute_frame_addr (offset, &next_scratch_regno); | |
3739 | reg_save_addr[which_scratch] = r; | |
3740 | } | |
3741 | else | |
3742 | { | |
3743 | /* Advance to the next stack slot to store this | |
3744 | register. */ | |
3745 | int stride = ROUND_ROBIN_SIZE * -UNITS_PER_WORD; | |
3746 | rtx p = gen_rtx_PLUS (Pmode, r, GEN_INT (stride)); | |
3747 | emit_insn (gen_rtx_SET (VOIDmode, r, p)); | |
3748 | } | |
3749 | ||
3750 | if (fp_copy_regno >= 0 && regno == HARD_FRAME_POINTER_REGNUM) | |
3751 | frame_emit_load (fp_copy_regno, r, NULL); | |
3752 | else | |
3753 | frame_emit_load (regno, r, &cfa_restores); | |
3754 | ||
3755 | offset -= UNITS_PER_WORD; | |
3756 | which_scratch = (which_scratch + 1) % ROUND_ROBIN_SIZE; | |
3757 | } | |
3758 | ||
3759 | if (!tilepro_current_function_is_leaf ()) | |
3760 | cfa_restores = | |
3761 | alloc_reg_note (REG_CFA_RESTORE, stack_pointer_rtx, cfa_restores); | |
3762 | ||
3763 | emit_insn (gen_blockage ()); | |
3764 | ||
c6cfe48f | 3765 | if (frame_pointer_needed) |
7ce78e23 | 3766 | { |
3767 | /* Restore the old stack pointer by copying from the frame | |
3768 | pointer. */ | |
3769 | insn = emit_insn (gen_sp_restore (stack_pointer_rtx, | |
3770 | hard_frame_pointer_rtx)); | |
3771 | RTX_FRAME_RELATED_P (insn) = 1; | |
3772 | REG_NOTES (insn) = cfa_restores; | |
3773 | add_reg_note (insn, REG_CFA_DEF_CFA, stack_pointer_rtx); | |
3774 | } | |
3775 | else | |
3776 | { | |
3777 | insn = emit_sp_adjust (total_size, &next_scratch_regno, true, | |
3778 | cfa_restores); | |
3779 | } | |
3780 | ||
c6cfe48f | 3781 | if (crtl->calls_eh_return) |
3782 | emit_insn (gen_sp_adjust (stack_pointer_rtx, stack_pointer_rtx, | |
3783 | EH_RETURN_STACKADJ_RTX)); | |
3784 | ||
7ce78e23 | 3785 | /* Restore the old frame pointer. */ |
3786 | if (frame_pointer_needed) | |
3787 | { | |
3788 | insn = emit_move_insn (hard_frame_pointer_rtx, | |
3789 | gen_rtx_REG (Pmode, fp_copy_regno)); | |
3790 | add_reg_note (insn, REG_CFA_RESTORE, hard_frame_pointer_rtx); | |
3791 | } | |
3792 | ||
3793 | /* Mark the pic registers as live outside of the function. */ | |
3794 | if (flag_pic) | |
3795 | { | |
3796 | emit_use (cfun->machine->text_label_rtx); | |
3797 | emit_use (cfun->machine->got_rtx); | |
3798 | } | |
3799 | ||
3800 | done: | |
3801 | if (!sibcall_p) | |
3802 | { | |
3803 | /* Emit the actual 'return' instruction. */ | |
3804 | emit_jump_insn (gen__return ()); | |
3805 | } | |
3806 | else | |
3807 | { | |
3808 | emit_use (gen_rtx_REG (Pmode, TILEPRO_LINK_REGNUM)); | |
3809 | } | |
3810 | ||
3811 | /* Mark all insns we just emitted as frame-related. */ | |
3812 | for (; last_insn != NULL_RTX; last_insn = next_insn (last_insn)) | |
3813 | RTX_FRAME_RELATED_P (last_insn) = 1; | |
3814 | } | |
3815 | ||
3816 | #undef ROUND_ROBIN_SIZE | |
3817 | ||
3818 | ||
3819 | /* Implement INITIAL_ELIMINATION_OFFSET. */ | |
3820 | int | |
3821 | tilepro_initial_elimination_offset (int from, int to) | |
3822 | { | |
3823 | int total_size = compute_total_frame_size (); | |
3824 | ||
3825 | if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM) | |
3826 | { | |
3827 | return (total_size - crtl->args.pretend_args_size | |
3828 | - tilepro_saved_regs_size ()); | |
3829 | } | |
3830 | else if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM) | |
3831 | { | |
3832 | return -(crtl->args.pretend_args_size + tilepro_saved_regs_size ()); | |
3833 | } | |
3834 | else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM) | |
3835 | { | |
3836 | return STACK_POINTER_OFFSET + total_size; | |
3837 | } | |
3838 | else if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM) | |
3839 | { | |
3840 | return STACK_POINTER_OFFSET; | |
3841 | } | |
3842 | else | |
3843 | gcc_unreachable (); | |
3844 | } | |
3845 | ||
3846 | ||
3847 | /* Return an RTX indicating where the return address to the | |
3848 | calling function can be found. */ | |
3849 | rtx | |
3850 | tilepro_return_addr (int count, rtx frame ATTRIBUTE_UNUSED) | |
3851 | { | |
3852 | if (count != 0) | |
3853 | return const0_rtx; | |
3854 | ||
3855 | return get_hard_reg_initial_val (Pmode, TILEPRO_LINK_REGNUM); | |
3856 | } | |
3857 | ||
3858 | ||
3859 | /* Implement EH_RETURN_HANDLER_RTX. */ | |
3860 | rtx | |
3861 | tilepro_eh_return_handler_rtx (void) | |
3862 | { | |
3863 | /* The MEM needs to be volatile to prevent it from being | |
3864 | deleted. */ | |
3865 | rtx tmp = gen_frame_mem (Pmode, hard_frame_pointer_rtx); | |
3866 | MEM_VOLATILE_P (tmp) = true; | |
3867 | return tmp; | |
3868 | } | |
3869 | \f | |
3870 | ||
3871 | ||
3872 | /* Registers */ | |
3873 | ||
3874 | /* Implemnet TARGET_CONDITIONAL_REGISTER_USAGE. */ | |
3875 | static void | |
3876 | tilepro_conditional_register_usage (void) | |
3877 | { | |
3878 | global_regs[TILEPRO_NETORDER_REGNUM] = 1; | |
3879 | /* TILEPRO_PIC_TEXT_LABEL_REGNUM is conditionally used. It is a | |
3880 | member of fixed_regs, and therefore must be member of | |
3881 | call_used_regs, but it is not a member of call_really_used_regs[] | |
3882 | because it is not clobbered by a call. */ | |
3883 | if (TILEPRO_PIC_TEXT_LABEL_REGNUM != INVALID_REGNUM) | |
3884 | { | |
3885 | fixed_regs[TILEPRO_PIC_TEXT_LABEL_REGNUM] = 1; | |
3886 | call_used_regs[TILEPRO_PIC_TEXT_LABEL_REGNUM] = 1; | |
3887 | } | |
3888 | if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM) | |
3889 | { | |
3890 | fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1; | |
3891 | call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1; | |
3892 | } | |
3893 | } | |
3894 | ||
3895 | ||
3896 | /* Implement TARGET_FRAME_POINTER_REQUIRED. */ | |
3897 | static bool | |
3898 | tilepro_frame_pointer_required (void) | |
3899 | { | |
3900 | return crtl->calls_eh_return || cfun->calls_alloca; | |
3901 | } | |
3902 | \f | |
3903 | ||
3904 | ||
3905 | /* Scheduling and reorg */ | |
3906 | ||
3907 | /* Return the length of INSN. LENGTH is the initial length computed | |
3908 | by attributes in the machine-description file. This is where we | |
3909 | account for bundles. */ | |
3910 | int | |
3911 | tilepro_adjust_insn_length (rtx insn, int length) | |
3912 | { | |
3913 | enum machine_mode mode = GET_MODE (insn); | |
3914 | ||
3915 | /* A non-termininating instruction in a bundle has length 0. */ | |
3916 | if (mode == SImode) | |
3917 | return 0; | |
3918 | ||
3919 | /* By default, there is not length adjustment. */ | |
3920 | return length; | |
3921 | } | |
3922 | ||
3923 | ||
3924 | /* Implement TARGET_SCHED_ISSUE_RATE. */ | |
3925 | static int | |
3926 | tilepro_issue_rate (void) | |
3927 | { | |
3928 | return 3; | |
3929 | } | |
3930 | ||
3931 | ||
3932 | /* Return the rtx for the jump target. */ | |
3933 | static rtx | |
3934 | get_jump_target (rtx branch) | |
3935 | { | |
3936 | if (CALL_P (branch)) | |
3937 | { | |
3938 | rtx call; | |
3939 | call = PATTERN (branch); | |
3940 | ||
3941 | if (GET_CODE (call) == PARALLEL) | |
3942 | call = XVECEXP (call, 0, 0); | |
3943 | ||
3944 | if (GET_CODE (call) == SET) | |
3945 | call = SET_SRC (call); | |
3946 | ||
3947 | if (GET_CODE (call) == CALL) | |
3948 | return XEXP (XEXP (call, 0), 0); | |
3949 | } | |
3950 | return 0; | |
3951 | } | |
3952 | ||
3953 | /* Implement TARGET_SCHED_ADJUST_COST. */ | |
3954 | static int | |
3955 | tilepro_sched_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost) | |
3956 | { | |
3957 | /* If we have a true dependence, INSN is a call, and DEP_INSN | |
3958 | defines a register that is needed by the call (argument or stack | |
3959 | pointer), set its latency to 0 so that it can be bundled with | |
3960 | the call. Explicitly check for and exclude the case when | |
3961 | DEP_INSN defines the target of the jump. */ | |
3962 | if (CALL_P (insn) && REG_NOTE_KIND (link) == REG_DEP_TRUE) | |
3963 | { | |
3964 | rtx target = get_jump_target (insn); | |
3965 | if (!REG_P (target) || !set_of (target, dep_insn)) | |
3966 | return 0; | |
3967 | } | |
3968 | ||
3969 | return cost; | |
3970 | } | |
3971 | ||
3972 | ||
3973 | /* Skip over irrelevant NOTEs and such and look for the next insn we | |
3974 | would consider bundling. */ | |
3975 | static rtx | |
3976 | next_insn_to_bundle (rtx r, rtx end) | |
3977 | { | |
3978 | for (; r != end; r = NEXT_INSN (r)) | |
3979 | { | |
3980 | if (NONDEBUG_INSN_P (r) | |
3981 | && GET_CODE (PATTERN (r)) != USE | |
3982 | && GET_CODE (PATTERN (r)) != CLOBBER) | |
3983 | return r; | |
3984 | } | |
3985 | ||
3986 | return NULL_RTX; | |
3987 | } | |
3988 | ||
3989 | ||
3990 | /* Go through all insns, and use the information generated during | |
3991 | scheduling to generate SEQUENCEs to represent bundles of | |
3992 | instructions issued simultaneously. */ | |
3993 | static void | |
3994 | tilepro_gen_bundles (void) | |
3995 | { | |
3996 | basic_block bb; | |
fc00614f | 3997 | FOR_EACH_BB_FN (bb, cfun) |
7ce78e23 | 3998 | { |
3999 | rtx insn, next; | |
4000 | rtx end = NEXT_INSN (BB_END (bb)); | |
4001 | ||
4002 | for (insn = next_insn_to_bundle (BB_HEAD (bb), end); insn; insn = next) | |
4003 | { | |
4004 | next = next_insn_to_bundle (NEXT_INSN (insn), end); | |
4005 | ||
4006 | /* Never wrap {} around inline asm. */ | |
4007 | if (GET_CODE (PATTERN (insn)) != ASM_INPUT) | |
4008 | { | |
4009 | if (next == NULL_RTX || GET_MODE (next) == TImode | |
4010 | /* NOTE: The scheduler incorrectly believes a call | |
4011 | insn can execute in the same cycle as the insn | |
4012 | after the call. This is of course impossible. | |
4013 | Really we need to fix the scheduler somehow, so | |
4014 | the code after the call gets scheduled | |
4015 | optimally. */ | |
4016 | || CALL_P (insn)) | |
4017 | { | |
4018 | /* Mark current insn as the end of a bundle. */ | |
4019 | PUT_MODE (insn, QImode); | |
4020 | } | |
4021 | else | |
4022 | { | |
4023 | /* Mark it as part of a bundle. */ | |
4024 | PUT_MODE (insn, SImode); | |
4025 | } | |
4026 | } | |
4027 | } | |
4028 | } | |
4029 | } | |
4030 | ||
4031 | ||
4032 | /* Helper function for tilepro_fixup_pcrel_references. */ | |
4033 | static void | |
4034 | replace_pc_relative_symbol_ref (rtx insn, rtx opnds[4], bool first_insn_p) | |
4035 | { | |
4036 | rtx new_insns; | |
4037 | ||
4038 | start_sequence (); | |
4039 | ||
4040 | if (flag_pic == 1) | |
4041 | { | |
4042 | if (!first_insn_p) | |
4043 | { | |
4044 | emit_insn (gen_add_got16 (opnds[0], tilepro_got_rtx (), | |
4045 | opnds[2])); | |
4046 | emit_insn (gen_insn_lw (opnds[0], opnds[0])); | |
4047 | } | |
4048 | } | |
4049 | else | |
4050 | { | |
4051 | if (first_insn_p) | |
4052 | { | |
4053 | emit_insn (gen_addhi_got32 (opnds[0], tilepro_got_rtx (), | |
4054 | opnds[2])); | |
4055 | } | |
4056 | else | |
4057 | { | |
4058 | emit_insn (gen_addlo_got32 (opnds[0], opnds[1], opnds[2])); | |
4059 | emit_insn (gen_insn_lw (opnds[0], opnds[0])); | |
4060 | } | |
4061 | } | |
4062 | ||
4063 | new_insns = get_insns (); | |
4064 | end_sequence (); | |
4065 | ||
4066 | if (new_insns) | |
4067 | emit_insn_before (new_insns, insn); | |
4068 | ||
4069 | delete_insn (insn); | |
4070 | } | |
4071 | ||
4072 | ||
4073 | /* Returns whether INSN is a pc-relative addli insn. */ | |
4074 | static bool | |
4075 | match_addli_pcrel (rtx insn) | |
4076 | { | |
4077 | rtx pattern = PATTERN (insn); | |
4078 | rtx unspec; | |
4079 | ||
4080 | if (GET_CODE (pattern) != SET) | |
4081 | return false; | |
4082 | ||
4083 | if (GET_CODE (SET_SRC (pattern)) != LO_SUM) | |
4084 | return false; | |
4085 | ||
4086 | if (GET_CODE (XEXP (SET_SRC (pattern), 1)) != CONST) | |
4087 | return false; | |
4088 | ||
4089 | unspec = XEXP (XEXP (SET_SRC (pattern), 1), 0); | |
4090 | ||
4091 | return (GET_CODE (unspec) == UNSPEC | |
4092 | && XINT (unspec, 1) == UNSPEC_PCREL_SYM); | |
4093 | } | |
4094 | ||
4095 | ||
4096 | /* Helper function for tilepro_fixup_pcrel_references. */ | |
4097 | static void | |
4098 | replace_addli_pcrel (rtx insn) | |
4099 | { | |
4100 | rtx pattern = PATTERN (insn); | |
4101 | rtx set_src; | |
4102 | rtx unspec; | |
4103 | rtx opnds[4]; | |
4104 | bool first_insn_p; | |
4105 | ||
4106 | gcc_assert (GET_CODE (pattern) == SET); | |
4107 | opnds[0] = SET_DEST (pattern); | |
4108 | ||
4109 | set_src = SET_SRC (pattern); | |
4110 | gcc_assert (GET_CODE (set_src) == LO_SUM); | |
4111 | gcc_assert (GET_CODE (XEXP (set_src, 1)) == CONST); | |
4112 | opnds[1] = XEXP (set_src, 0); | |
4113 | ||
4114 | unspec = XEXP (XEXP (set_src, 1), 0); | |
4115 | gcc_assert (GET_CODE (unspec) == UNSPEC); | |
4116 | gcc_assert (XINT (unspec, 1) == UNSPEC_PCREL_SYM); | |
4117 | opnds[2] = XVECEXP (unspec, 0, 0); | |
4118 | opnds[3] = XVECEXP (unspec, 0, 1); | |
4119 | ||
4120 | /* We only need to replace SYMBOL_REFs, not LABEL_REFs. */ | |
4121 | if (GET_CODE (opnds[2]) != SYMBOL_REF) | |
4122 | return; | |
4123 | ||
4124 | first_insn_p = (opnds[1] == tilepro_text_label_rtx ()); | |
4125 | ||
4126 | replace_pc_relative_symbol_ref (insn, opnds, first_insn_p); | |
4127 | } | |
4128 | ||
4129 | ||
4130 | /* Returns whether INSN is a pc-relative auli insn. */ | |
4131 | static bool | |
4132 | match_auli_pcrel (rtx insn) | |
4133 | { | |
4134 | rtx pattern = PATTERN (insn); | |
4135 | rtx high; | |
4136 | rtx unspec; | |
4137 | ||
4138 | if (GET_CODE (pattern) != SET) | |
4139 | return false; | |
4140 | ||
4141 | if (GET_CODE (SET_SRC (pattern)) != PLUS) | |
4142 | return false; | |
4143 | ||
4144 | high = XEXP (SET_SRC (pattern), 1); | |
4145 | ||
4146 | if (GET_CODE (high) != HIGH | |
4147 | || GET_CODE (XEXP (high, 0)) != CONST) | |
4148 | return false; | |
4149 | ||
4150 | unspec = XEXP (XEXP (high, 0), 0); | |
4151 | ||
4152 | return (GET_CODE (unspec) == UNSPEC | |
4153 | && XINT (unspec, 1) == UNSPEC_PCREL_SYM); | |
4154 | } | |
4155 | ||
4156 | ||
4157 | /* Helper function for tilepro_fixup_pcrel_references. */ | |
4158 | static void | |
4159 | replace_auli_pcrel (rtx insn) | |
4160 | { | |
4161 | rtx pattern = PATTERN (insn); | |
4162 | rtx set_src; | |
4163 | rtx high; | |
4164 | rtx unspec; | |
4165 | rtx opnds[4]; | |
4166 | bool first_insn_p; | |
4167 | ||
4168 | gcc_assert (GET_CODE (pattern) == SET); | |
4169 | opnds[0] = SET_DEST (pattern); | |
4170 | ||
4171 | set_src = SET_SRC (pattern); | |
4172 | gcc_assert (GET_CODE (set_src) == PLUS); | |
4173 | opnds[1] = XEXP (set_src, 0); | |
4174 | ||
4175 | high = XEXP (set_src, 1); | |
4176 | gcc_assert (GET_CODE (high) == HIGH); | |
4177 | gcc_assert (GET_CODE (XEXP (high, 0)) == CONST); | |
4178 | ||
4179 | unspec = XEXP (XEXP (high, 0), 0); | |
4180 | gcc_assert (GET_CODE (unspec) == UNSPEC); | |
4181 | gcc_assert (XINT (unspec, 1) == UNSPEC_PCREL_SYM); | |
4182 | opnds[2] = XVECEXP (unspec, 0, 0); | |
4183 | opnds[3] = XVECEXP (unspec, 0, 1); | |
4184 | ||
4185 | /* We only need to replace SYMBOL_REFs, not LABEL_REFs. */ | |
4186 | if (GET_CODE (opnds[2]) != SYMBOL_REF) | |
4187 | return; | |
4188 | ||
4189 | first_insn_p = (opnds[1] == tilepro_text_label_rtx ()); | |
4190 | ||
4191 | replace_pc_relative_symbol_ref (insn, opnds, first_insn_p); | |
4192 | } | |
4193 | ||
4194 | ||
4195 | /* We generate PC relative SYMBOL_REFs as an optimization, to avoid | |
4196 | going through the GOT when the symbol is local to the compilation | |
4197 | unit. But such a symbol requires that the common text_label that | |
4198 | we generate at the beginning of the function be in the same section | |
4199 | as the reference to the SYMBOL_REF. This may not be true if we | |
4200 | generate hot/cold sections. This function looks for such cases and | |
4201 | replaces such references with the longer sequence going through the | |
4202 | GOT. | |
4203 | ||
4204 | We expect one of the following two instruction sequences: | |
4205 | addli tmp1, txt_label_reg, lo16(sym - txt_label) | |
4206 | auli tmp2, tmp1, ha16(sym - txt_label) | |
4207 | ||
4208 | auli tmp1, txt_label_reg, ha16(sym - txt_label) | |
4209 | addli tmp2, tmp1, lo16(sym - txt_label) | |
4210 | ||
4211 | If we're compiling -fpic, we replace the first instruction with | |
4212 | nothing, and the second instruction with: | |
4213 | ||
4214 | addli tmp2, got_rtx, got(sym) | |
4215 | lw tmp2, tmp2 | |
4216 | ||
4217 | If we're compiling -fPIC, we replace the first instruction with: | |
4218 | ||
4219 | auli tmp1, got_rtx, got_ha16(sym) | |
4220 | ||
4221 | and the second instruction with: | |
4222 | ||
4223 | addli tmp2, tmp1, got_lo16(sym) | |
4224 | lw tmp2, tmp2 | |
4225 | ||
4226 | Note that we're careful to disturb the instruction sequence as | |
4227 | little as possible, since it's very late in the compilation | |
4228 | process. | |
4229 | */ | |
4230 | static void | |
4231 | tilepro_fixup_pcrel_references (void) | |
4232 | { | |
4233 | rtx insn, next_insn; | |
4234 | bool same_section_as_entry = true; | |
4235 | ||
4236 | for (insn = get_insns (); insn; insn = next_insn) | |
4237 | { | |
4238 | next_insn = NEXT_INSN (insn); | |
4239 | ||
4240 | if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS) | |
4241 | { | |
4242 | same_section_as_entry = !same_section_as_entry; | |
4243 | continue; | |
4244 | } | |
4245 | ||
4246 | if (same_section_as_entry) | |
4247 | continue; | |
4248 | ||
4249 | if (!(INSN_P (insn) | |
4250 | && GET_CODE (PATTERN (insn)) != USE | |
4251 | && GET_CODE (PATTERN (insn)) != CLOBBER)) | |
4252 | continue; | |
4253 | ||
4254 | if (match_addli_pcrel (insn)) | |
4255 | replace_addli_pcrel (insn); | |
4256 | else if (match_auli_pcrel (insn)) | |
4257 | replace_auli_pcrel (insn); | |
4258 | } | |
4259 | } | |
4260 | ||
4261 | ||
4262 | /* Ensure that no var tracking notes are emitted in the middle of a | |
4263 | three-instruction bundle. */ | |
4264 | static void | |
4265 | reorder_var_tracking_notes (void) | |
4266 | { | |
4267 | basic_block bb; | |
fc00614f | 4268 | FOR_EACH_BB_FN (bb, cfun) |
7ce78e23 | 4269 | { |
4270 | rtx insn, next; | |
4271 | rtx queue = NULL_RTX; | |
4272 | bool in_bundle = false; | |
4273 | ||
4274 | for (insn = BB_HEAD (bb); insn != BB_END (bb); insn = next) | |
4275 | { | |
4276 | next = NEXT_INSN (insn); | |
4277 | ||
4278 | if (INSN_P (insn)) | |
4279 | { | |
4280 | /* Emit queued up notes at the last instruction of a bundle. */ | |
4281 | if (GET_MODE (insn) == QImode) | |
4282 | { | |
4283 | while (queue) | |
4284 | { | |
4285 | rtx next_queue = PREV_INSN (queue); | |
4286 | PREV_INSN (NEXT_INSN (insn)) = queue; | |
4287 | NEXT_INSN (queue) = NEXT_INSN (insn); | |
4288 | NEXT_INSN (insn) = queue; | |
4289 | PREV_INSN (queue) = insn; | |
4290 | queue = next_queue; | |
4291 | } | |
4292 | in_bundle = false; | |
4293 | } | |
4294 | else if (GET_MODE (insn) == SImode) | |
4295 | in_bundle = true; | |
4296 | } | |
4297 | else if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_VAR_LOCATION) | |
4298 | { | |
4299 | if (in_bundle) | |
4300 | { | |
4301 | rtx prev = PREV_INSN (insn); | |
4302 | PREV_INSN (next) = prev; | |
4303 | NEXT_INSN (prev) = next; | |
4304 | ||
4305 | PREV_INSN (insn) = queue; | |
4306 | queue = insn; | |
4307 | } | |
4308 | } | |
4309 | } | |
4310 | } | |
4311 | } | |
4312 | ||
4313 | ||
4314 | /* Perform machine dependent operations on the rtl chain INSNS. */ | |
4315 | static void | |
4316 | tilepro_reorg (void) | |
4317 | { | |
4318 | /* We are freeing block_for_insn in the toplev to keep compatibility | |
4319 | with old MDEP_REORGS that are not CFG based. Recompute it | |
4320 | now. */ | |
4321 | compute_bb_for_insn (); | |
4322 | ||
4323 | if (flag_reorder_blocks_and_partition) | |
4324 | { | |
4325 | tilepro_fixup_pcrel_references (); | |
4326 | } | |
4327 | ||
4328 | if (flag_schedule_insns_after_reload) | |
4329 | { | |
4330 | split_all_insns (); | |
4331 | ||
4332 | timevar_push (TV_SCHED2); | |
4333 | schedule_insns (); | |
4334 | timevar_pop (TV_SCHED2); | |
4335 | ||
4336 | /* Examine the schedule to group into bundles. */ | |
4337 | tilepro_gen_bundles (); | |
4338 | } | |
4339 | ||
4340 | df_analyze (); | |
4341 | ||
4342 | if (flag_var_tracking) | |
4343 | { | |
4344 | timevar_push (TV_VAR_TRACKING); | |
4345 | variable_tracking_main (); | |
4346 | reorder_var_tracking_notes (); | |
4347 | timevar_pop (TV_VAR_TRACKING); | |
4348 | } | |
4349 | ||
4350 | df_finish_pass (false); | |
4351 | } | |
4352 | \f | |
4353 | ||
4354 | ||
4355 | /* Assembly */ | |
4356 | ||
4357 | /* Select a format to encode pointers in exception handling data. | |
4358 | CODE is 0 for data, 1 for code labels, 2 for function pointers. | |
4359 | GLOBAL is true if the symbol may be affected by dynamic | |
4360 | relocations. */ | |
4361 | int | |
4362 | tilepro_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED, int global) | |
4363 | { | |
b429d641 | 4364 | return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4; |
7ce78e23 | 4365 | } |
4366 | ||
4367 | ||
4368 | /* Implement TARGET_ASM_OUTPUT_MI_THUNK. */ | |
4369 | static void | |
4370 | tilepro_asm_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED, | |
4371 | HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset, | |
4372 | tree function) | |
4373 | { | |
4374 | rtx this_rtx, insn, funexp; | |
4375 | ||
4376 | /* Pretend to be a post-reload pass while generating rtl. */ | |
4377 | reload_completed = 1; | |
4378 | ||
4379 | /* Mark the end of the (empty) prologue. */ | |
4380 | emit_note (NOTE_INSN_PROLOGUE_END); | |
4381 | ||
4382 | /* Find the "this" pointer. If the function returns a structure, | |
4383 | the structure return pointer is in $1. */ | |
4384 | if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function)) | |
4385 | this_rtx = gen_rtx_REG (Pmode, 1); | |
4386 | else | |
4387 | this_rtx = gen_rtx_REG (Pmode, 0); | |
4388 | ||
4389 | /* Add DELTA to THIS_RTX. */ | |
4390 | emit_insn (gen_addsi3 (this_rtx, this_rtx, GEN_INT (delta))); | |
4391 | ||
4392 | /* If needed, add *(*THIS_RTX + VCALL_OFFSET) to THIS_RTX. */ | |
4393 | if (vcall_offset) | |
4394 | { | |
4395 | rtx tmp; | |
4396 | ||
4397 | tmp = gen_rtx_REG (Pmode, 29); | |
4398 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, this_rtx)); | |
4399 | ||
4400 | emit_insn (gen_addsi3 (tmp, tmp, GEN_INT (vcall_offset))); | |
4401 | ||
4402 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp)); | |
4403 | ||
4404 | emit_insn (gen_addsi3 (this_rtx, this_rtx, tmp)); | |
4405 | } | |
4406 | ||
4407 | /* Generate a tail call to the target function. */ | |
4408 | if (!TREE_USED (function)) | |
4409 | { | |
4410 | assemble_external (function); | |
4411 | TREE_USED (function) = 1; | |
4412 | } | |
4413 | funexp = XEXP (DECL_RTL (function), 0); | |
4414 | funexp = gen_rtx_MEM (FUNCTION_MODE, funexp); | |
4415 | insn = emit_call_insn (gen_sibcall (funexp, const0_rtx)); | |
4416 | SIBLING_CALL_P (insn) = 1; | |
4417 | ||
4418 | /* Run just enough of rest_of_compilation to get the insns emitted. | |
4419 | There's not really enough bulk here to make other passes such as | |
4420 | instruction scheduling worth while. Note that use_thunk calls | |
4421 | assemble_start_function and assemble_end_function. | |
4422 | ||
4423 | We don't currently bundle, but the instruciton sequence is all | |
4424 | serial except for the tail call, so we're only wasting one cycle. | |
4425 | */ | |
4426 | insn = get_insns (); | |
7ce78e23 | 4427 | shorten_branches (insn); |
4428 | final_start_function (insn, file, 1); | |
4429 | final (insn, file, 1); | |
4430 | final_end_function (); | |
4431 | ||
4432 | /* Stop pretending to be a post-reload pass. */ | |
4433 | reload_completed = 0; | |
4434 | } | |
4435 | ||
4436 | ||
4437 | /* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE. */ | |
4438 | static void | |
4439 | tilepro_asm_trampoline_template (FILE *file) | |
4440 | { | |
4441 | fprintf (file, "\tlnk r10\n"); | |
4442 | fprintf (file, "\taddi r10, r10, 32\n"); | |
4443 | fprintf (file, "\tlwadd r11, r10, %d\n", GET_MODE_SIZE (ptr_mode)); | |
4444 | fprintf (file, "\tlw r10, r10\n"); | |
4445 | fprintf (file, "\tjr r11\n"); | |
4446 | fprintf (file, "\t.word 0 # <function address>\n"); | |
4447 | fprintf (file, "\t.word 0 # <static chain value>\n"); | |
4448 | } | |
4449 | ||
4450 | ||
4451 | /* Implement TARGET_TRAMPOLINE_INIT. */ | |
4452 | static void | |
4453 | tilepro_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain) | |
4454 | { | |
4455 | rtx fnaddr, chaddr; | |
4456 | rtx mem; | |
4457 | rtx begin_addr, end_addr; | |
4458 | int ptr_mode_size = GET_MODE_SIZE (ptr_mode); | |
4459 | ||
4460 | fnaddr = copy_to_reg (XEXP (DECL_RTL (fndecl), 0)); | |
4461 | chaddr = copy_to_reg (static_chain); | |
4462 | ||
4463 | emit_block_move (m_tramp, assemble_trampoline_template (), | |
4464 | GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL); | |
4465 | ||
4466 | mem = adjust_address (m_tramp, ptr_mode, | |
4467 | TRAMPOLINE_SIZE - 2 * ptr_mode_size); | |
4468 | emit_move_insn (mem, fnaddr); | |
4469 | mem = adjust_address (m_tramp, ptr_mode, | |
4470 | TRAMPOLINE_SIZE - ptr_mode_size); | |
4471 | emit_move_insn (mem, chaddr); | |
4472 | ||
4473 | /* Get pointers to the beginning and end of the code block. */ | |
4474 | begin_addr = force_reg (Pmode, XEXP (m_tramp, 0)); | |
29c05e22 | 4475 | end_addr = force_reg (Pmode, plus_constant (Pmode, XEXP (m_tramp, 0), |
7ce78e23 | 4476 | TRAMPOLINE_SIZE)); |
4477 | ||
4478 | emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"), | |
4479 | LCT_NORMAL, VOIDmode, 2, begin_addr, Pmode, | |
4480 | end_addr, Pmode); | |
4481 | } | |
4482 | ||
4483 | ||
4484 | /* Implement TARGET_PRINT_OPERAND. */ | |
4485 | static void | |
4486 | tilepro_print_operand (FILE *file, rtx x, int code) | |
4487 | { | |
4488 | switch (code) | |
4489 | { | |
4490 | case 'c': | |
4491 | /* Print the compare operator opcode for conditional moves. */ | |
4492 | switch (GET_CODE (x)) | |
4493 | { | |
4494 | case EQ: | |
4495 | fputs ("z", file); | |
4496 | break; | |
4497 | case NE: | |
4498 | fputs ("nz", file); | |
4499 | break; | |
4500 | default: | |
4501 | output_operand_lossage ("invalid %%c operand"); | |
4502 | } | |
4503 | return; | |
4504 | ||
4505 | case 'C': | |
4506 | /* Print the compare operator opcode for conditional moves. */ | |
4507 | switch (GET_CODE (x)) | |
4508 | { | |
4509 | case EQ: | |
4510 | fputs ("nz", file); | |
4511 | break; | |
4512 | case NE: | |
4513 | fputs ("z", file); | |
4514 | break; | |
4515 | default: | |
4516 | output_operand_lossage ("invalid %%C operand"); | |
4517 | } | |
4518 | return; | |
4519 | ||
4520 | case 'h': | |
4521 | { | |
4522 | /* Print the high 16 bits of a 32-bit constant. */ | |
4523 | HOST_WIDE_INT i; | |
4524 | if (CONST_INT_P (x)) | |
4525 | i = INTVAL (x); | |
4526 | else if (GET_CODE (x) == CONST_DOUBLE) | |
4527 | i = CONST_DOUBLE_LOW (x); | |
4528 | else | |
4529 | { | |
4530 | output_operand_lossage ("invalid %%h operand"); | |
4531 | return; | |
4532 | } | |
4533 | i = trunc_int_for_mode (i >> 16, HImode); | |
4534 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, i); | |
4535 | return; | |
4536 | } | |
4537 | ||
4538 | case 'H': | |
4539 | { | |
4540 | rtx addr = NULL; | |
4541 | const char *opstr = NULL; | |
4542 | bool pcrel = false; | |
4543 | if (GET_CODE (x) == CONST | |
4544 | && GET_CODE (XEXP (x, 0)) == UNSPEC) | |
4545 | { | |
4546 | addr = XVECEXP (XEXP (x, 0), 0, 0); | |
4547 | switch (XINT (XEXP (x, 0), 1)) | |
4548 | { | |
4549 | case UNSPEC_GOT32_SYM: | |
4550 | opstr = "got_ha16"; | |
4551 | break; | |
4552 | case UNSPEC_PCREL_SYM: | |
4553 | opstr = "ha16"; | |
4554 | pcrel = true; | |
4555 | break; | |
4556 | case UNSPEC_TLS_GD: | |
4557 | opstr = "tls_gd_ha16"; | |
4558 | break; | |
4559 | case UNSPEC_TLS_IE: | |
4560 | opstr = "tls_ie_ha16"; | |
4561 | break; | |
4562 | case UNSPEC_TLS_LE: | |
4563 | opstr = "tls_le_ha16"; | |
4564 | break; | |
4565 | default: | |
4566 | output_operand_lossage ("invalid %%H operand"); | |
4567 | } | |
4568 | } | |
4569 | else | |
4570 | { | |
4571 | addr = x; | |
4572 | opstr = "ha16"; | |
4573 | } | |
4574 | ||
4575 | fputs (opstr, file); | |
4576 | fputc ('(', file); | |
4577 | output_addr_const (file, addr); | |
4578 | ||
4579 | if (pcrel) | |
4580 | { | |
4581 | rtx addr2 = XVECEXP (XEXP (x, 0), 0, 1); | |
4582 | fputs (" - " , file); | |
4583 | output_addr_const (file, addr2); | |
4584 | } | |
4585 | ||
4586 | fputc (')', file); | |
4587 | return; | |
4588 | } | |
4589 | ||
4590 | case 'I': | |
4591 | /* Print an auto-inc memory operand. */ | |
4592 | if (!MEM_P (x)) | |
4593 | { | |
4594 | output_operand_lossage ("invalid %%I operand"); | |
4595 | return; | |
4596 | } | |
4597 | ||
4598 | output_memory_reference_mode = GET_MODE (x); | |
4599 | output_memory_autoinc_first = true; | |
4600 | output_address (XEXP (x, 0)); | |
4601 | output_memory_reference_mode = VOIDmode; | |
4602 | return; | |
4603 | ||
4604 | case 'i': | |
4605 | /* Print an auto-inc memory operand. */ | |
4606 | if (!MEM_P (x)) | |
4607 | { | |
4608 | output_operand_lossage ("invalid %%i operand"); | |
4609 | return; | |
4610 | } | |
4611 | ||
4612 | output_memory_reference_mode = GET_MODE (x); | |
4613 | output_memory_autoinc_first = false; | |
4614 | output_address (XEXP (x, 0)); | |
4615 | output_memory_reference_mode = VOIDmode; | |
4616 | return; | |
4617 | ||
4618 | case 'j': | |
4619 | { | |
4620 | /* Print the low 8 bits of a constant. */ | |
4621 | HOST_WIDE_INT i; | |
4622 | if (CONST_INT_P (x)) | |
4623 | i = INTVAL (x); | |
4624 | else if (GET_CODE (x) == CONST_DOUBLE) | |
4625 | i = CONST_DOUBLE_LOW (x); | |
4626 | else if (GET_CODE (x) == CONST_VECTOR | |
4627 | && CONST_INT_P (CONST_VECTOR_ELT (x, 0))) | |
4628 | i = INTVAL (CONST_VECTOR_ELT (x, 0)); | |
4629 | else | |
4630 | { | |
4631 | output_operand_lossage ("invalid %%j operand"); | |
4632 | return; | |
4633 | } | |
4634 | i = trunc_int_for_mode (i, QImode); | |
4635 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, i); | |
4636 | return; | |
4637 | } | |
4638 | ||
4639 | case 'L': | |
4640 | { | |
4641 | rtx addr = NULL; | |
4642 | const char *opstr = NULL; | |
4643 | bool pcrel = false; | |
4644 | if (GET_CODE (x) == CONST | |
4645 | && GET_CODE (XEXP (x, 0)) == UNSPEC) | |
4646 | { | |
4647 | addr = XVECEXP (XEXP (x, 0), 0, 0); | |
4648 | switch (XINT (XEXP (x, 0), 1)) | |
4649 | { | |
4650 | case UNSPEC_GOT16_SYM: | |
4651 | opstr = "got"; | |
4652 | break; | |
4653 | case UNSPEC_GOT32_SYM: | |
4654 | opstr = "got_lo16"; | |
4655 | break; | |
4656 | case UNSPEC_PCREL_SYM: | |
4657 | opstr = "lo16"; | |
4658 | pcrel = true; | |
4659 | break; | |
4660 | case UNSPEC_TLS_GD: | |
4661 | opstr = "tls_gd_lo16"; | |
4662 | break; | |
4663 | case UNSPEC_TLS_IE: | |
4664 | opstr = "tls_ie_lo16"; | |
4665 | break; | |
4666 | case UNSPEC_TLS_LE: | |
4667 | opstr = "tls_le_lo16"; | |
4668 | break; | |
4669 | default: | |
4670 | output_operand_lossage ("invalid %%L operand"); | |
4671 | } | |
4672 | } | |
4673 | else | |
4674 | { | |
4675 | addr = x; | |
4676 | opstr = "lo16"; | |
4677 | } | |
4678 | ||
4679 | fputs (opstr, file); | |
4680 | fputc ('(', file); | |
4681 | output_addr_const (file, addr); | |
4682 | ||
4683 | if (pcrel) | |
4684 | { | |
4685 | rtx addr2 = XVECEXP (XEXP (x, 0), 0, 1); | |
4686 | fputs (" - " , file); | |
4687 | output_addr_const (file, addr2); | |
4688 | } | |
4689 | ||
4690 | fputc (')', file); | |
4691 | return; | |
4692 | } | |
4693 | ||
4694 | case 'p': | |
4695 | if (GET_CODE (x) == SYMBOL_REF) | |
4696 | { | |
4697 | if (flag_pic && !SYMBOL_REF_LOCAL_P (x)) | |
4698 | fprintf (file, "plt("); | |
4699 | output_addr_const (file, x); | |
4700 | if (flag_pic && !SYMBOL_REF_LOCAL_P (x)) | |
4701 | fprintf (file, ")"); | |
4702 | } | |
4703 | else | |
4704 | output_addr_const (file, x); | |
4705 | return; | |
4706 | ||
4707 | case 'P': | |
4708 | { | |
4709 | /* Print a 32-bit constant plus one. */ | |
4710 | HOST_WIDE_INT i; | |
4711 | if (!CONST_INT_P (x)) | |
4712 | { | |
4713 | output_operand_lossage ("invalid %%P operand"); | |
4714 | return; | |
4715 | } | |
4716 | i = trunc_int_for_mode (INTVAL (x) + 1, SImode); | |
4717 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, i); | |
4718 | return; | |
4719 | } | |
4720 | ||
4721 | case 'M': | |
4722 | { | |
4723 | /* Print an mm-style bit range. */ | |
4724 | int first_bit, last_bit; | |
4725 | ||
4726 | if (!CONST_INT_P (x) | |
4727 | || !tilepro_bitfield_operand_p (INTVAL (x), &first_bit, | |
4728 | &last_bit)) | |
4729 | { | |
4730 | output_operand_lossage ("invalid %%M operand"); | |
4731 | return; | |
4732 | } | |
4733 | ||
4734 | fprintf (file, "%d, %d", first_bit, last_bit); | |
4735 | return; | |
4736 | } | |
4737 | ||
4738 | case 'N': | |
4739 | { | |
4740 | const char *reg = NULL; | |
4741 | ||
4742 | /* Print a network register. */ | |
4743 | if (!CONST_INT_P (x)) | |
4744 | { | |
4745 | output_operand_lossage ("invalid %%N operand"); | |
4746 | return; | |
4747 | } | |
4748 | ||
4749 | switch (INTVAL (x)) | |
4750 | { | |
4751 | case TILEPRO_NETREG_IDN0: reg = "idn0"; break; | |
4752 | case TILEPRO_NETREG_IDN1: reg = "idn1"; break; | |
4753 | case TILEPRO_NETREG_SN: reg = "sn"; break; | |
4754 | case TILEPRO_NETREG_UDN0: reg = "udn0"; break; | |
4755 | case TILEPRO_NETREG_UDN1: reg = "udn1"; break; | |
4756 | case TILEPRO_NETREG_UDN2: reg = "udn2"; break; | |
4757 | case TILEPRO_NETREG_UDN3: reg = "udn3"; break; | |
4758 | default: gcc_unreachable (); | |
4759 | } | |
4760 | ||
4761 | fprintf (file, reg); | |
4762 | return; | |
4763 | } | |
4764 | ||
4765 | case 't': | |
4766 | { | |
4767 | /* Log base 2 of a power of two. */ | |
4768 | HOST_WIDE_INT i; | |
4769 | HOST_WIDE_INT n; | |
4770 | ||
4771 | if (!CONST_INT_P (x)) | |
4772 | { | |
4773 | output_operand_lossage ("invalid %%t operand"); | |
4774 | return; | |
4775 | } | |
4776 | n = trunc_int_for_mode (INTVAL (x), SImode); | |
4777 | i = exact_log2 (n); | |
4778 | if (i < 0) | |
4779 | { | |
4780 | output_operand_lossage ("invalid %%t operand '" | |
4781 | HOST_WIDE_INT_PRINT_DEC "'", n); | |
4782 | return; | |
4783 | } | |
4784 | ||
4785 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, i); | |
4786 | return; | |
4787 | } | |
4788 | break; | |
4789 | ||
4790 | case 'r': | |
4791 | /* In this case we need a register. Use 'zero' if the | |
4792 | operand is const0_rtx. */ | |
4793 | if (x == const0_rtx | |
4794 | || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x)))) | |
4795 | { | |
4796 | fputs ("zero", file); | |
4797 | return; | |
4798 | } | |
4799 | else if (!REG_P (x)) | |
4800 | { | |
4801 | output_operand_lossage ("invalid %%r operand"); | |
4802 | return; | |
4803 | } | |
4804 | /* FALLTHRU */ | |
4805 | ||
4806 | case 0: | |
4807 | if (REG_P (x)) | |
4808 | { | |
4809 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
4810 | return; | |
4811 | } | |
4812 | else if (MEM_P (x)) | |
4813 | { | |
4814 | output_memory_reference_mode = VOIDmode; | |
4815 | output_address (XEXP (x, 0)); | |
4816 | return; | |
4817 | } | |
4818 | else | |
4819 | { | |
4820 | output_addr_const (file, x); | |
4821 | return; | |
4822 | } | |
4823 | break; | |
4824 | } | |
4825 | ||
4826 | debug_rtx (x); | |
4827 | output_operand_lossage ("unable to print out operand yet; code == %d (%c)", | |
4828 | code, code); | |
4829 | } | |
4830 | ||
4831 | ||
4832 | /* Implement TARGET_PRINT_OPERAND_ADDRESS. */ | |
4833 | static void | |
4834 | tilepro_print_operand_address (FILE *file, rtx addr) | |
4835 | { | |
4836 | if (GET_CODE (addr) == POST_DEC | |
4837 | || GET_CODE (addr) == POST_INC) | |
4838 | { | |
4839 | int offset = GET_MODE_SIZE (output_memory_reference_mode); | |
4840 | ||
4841 | gcc_assert (output_memory_reference_mode != VOIDmode); | |
4842 | ||
4843 | if (output_memory_autoinc_first) | |
4844 | fprintf (file, "%s", reg_names[REGNO (XEXP (addr, 0))]); | |
4845 | else | |
4846 | fprintf (file, "%d", | |
4847 | GET_CODE (addr) == POST_DEC ? -offset : offset); | |
4848 | } | |
4849 | else if (GET_CODE (addr) == POST_MODIFY) | |
4850 | { | |
4851 | gcc_assert (output_memory_reference_mode != VOIDmode); | |
4852 | ||
4853 | gcc_assert (GET_CODE (XEXP (addr, 1)) == PLUS); | |
4854 | ||
4855 | if (output_memory_autoinc_first) | |
4856 | fprintf (file, "%s", reg_names[REGNO (XEXP (addr, 0))]); | |
4857 | else | |
4858 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, | |
4859 | INTVAL (XEXP (XEXP (addr, 1), 1))); | |
4860 | } | |
4861 | else | |
4862 | tilepro_print_operand (file, addr, 'r'); | |
4863 | } | |
4864 | ||
4865 | ||
4866 | /* Machine mode of current insn, for determining curly brace | |
4867 | placement. */ | |
4868 | static enum machine_mode insn_mode; | |
4869 | ||
4870 | ||
4871 | /* Implement FINAL_PRESCAN_INSN. This is used to emit bundles. */ | |
4872 | void | |
4873 | tilepro_final_prescan_insn (rtx insn) | |
4874 | { | |
4875 | /* Record this for tilepro_asm_output_opcode to examine. */ | |
4876 | insn_mode = GET_MODE (insn); | |
4877 | } | |
4878 | ||
4879 | ||
4880 | /* While emitting asm, are we currently inside '{' for a bundle? */ | |
4881 | static bool tilepro_in_bundle = false; | |
4882 | ||
4883 | /* Implement ASM_OUTPUT_OPCODE. Prepend/append curly braces as | |
4884 | appropriate given the bundling information recorded by | |
4885 | tilepro_gen_bundles. */ | |
4886 | const char * | |
4887 | tilepro_asm_output_opcode (FILE *stream, const char *code) | |
4888 | { | |
4889 | bool pseudo = !strcmp (code, "pseudo"); | |
4890 | ||
4891 | if (!tilepro_in_bundle && insn_mode == SImode) | |
4892 | { | |
4893 | /* Start a new bundle. */ | |
4894 | fprintf (stream, "{\n\t"); | |
4895 | tilepro_in_bundle = true; | |
4896 | } | |
4897 | ||
4898 | if (tilepro_in_bundle && insn_mode == QImode) | |
4899 | { | |
4900 | /* Close an existing bundle. */ | |
4901 | static char buf[100]; | |
4902 | ||
4903 | gcc_assert (strlen (code) + 3 + 1 < sizeof (buf)); | |
4904 | ||
4905 | strcpy (buf, pseudo ? "" : code); | |
4906 | strcat (buf, "\n\t}"); | |
4907 | tilepro_in_bundle = false; | |
4908 | ||
4909 | return buf; | |
4910 | } | |
4911 | else | |
4912 | { | |
4913 | return pseudo ? "" : code; | |
4914 | } | |
4915 | } | |
4916 | ||
4917 | ||
4918 | /* Output assembler code to FILE to increment profiler label # LABELNO | |
4919 | for profiling a function entry. */ | |
4920 | void | |
4921 | tilepro_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED) | |
4922 | { | |
4923 | if (tilepro_in_bundle) | |
4924 | { | |
4925 | fprintf (file, "\t}\n"); | |
4926 | } | |
4927 | ||
4928 | if (flag_pic) | |
4929 | { | |
4930 | fprintf (file, | |
4931 | "\t{\n" | |
4932 | "\tmove\tr10, lr\n" | |
d34cf22c | 4933 | "\tjal\tplt(%s)\n" |
7ce78e23 | 4934 | "\t}\n", MCOUNT_NAME); |
4935 | } | |
4936 | else | |
4937 | { | |
4938 | fprintf (file, | |
4939 | "\t{\n" | |
4940 | "\tmove\tr10, lr\n" | |
4941 | "\tjal\t%s\n" | |
4942 | "\t}\n", MCOUNT_NAME); | |
4943 | } | |
4944 | ||
4945 | tilepro_in_bundle = false; | |
4946 | } | |
4947 | ||
4948 | ||
4949 | /* Implement TARGET_ASM_FILE_END. */ | |
4950 | static void | |
4951 | tilepro_file_end (void) | |
4952 | { | |
4953 | if (NEED_INDICATE_EXEC_STACK) | |
4954 | file_end_indicate_exec_stack (); | |
4955 | } | |
4956 | ||
4957 | ||
4958 | #undef TARGET_HAVE_TLS | |
4959 | #define TARGET_HAVE_TLS HAVE_AS_TLS | |
4960 | ||
4961 | #undef TARGET_OPTION_OVERRIDE | |
4962 | #define TARGET_OPTION_OVERRIDE tilepro_option_override | |
4963 | ||
4964 | #undef TARGET_SCALAR_MODE_SUPPORTED_P | |
4965 | #define TARGET_SCALAR_MODE_SUPPORTED_P tilepro_scalar_mode_supported_p | |
4966 | ||
4967 | #undef TARGET_VECTOR_MODE_SUPPORTED_P | |
4968 | #define TARGET_VECTOR_MODE_SUPPORTED_P tile_vector_mode_supported_p | |
4969 | ||
4970 | #undef TARGET_CANNOT_FORCE_CONST_MEM | |
4971 | #define TARGET_CANNOT_FORCE_CONST_MEM tilepro_cannot_force_const_mem | |
4972 | ||
4973 | #undef TARGET_FUNCTION_OK_FOR_SIBCALL | |
4974 | #define TARGET_FUNCTION_OK_FOR_SIBCALL tilepro_function_ok_for_sibcall | |
4975 | ||
4976 | #undef TARGET_PASS_BY_REFERENCE | |
4977 | #define TARGET_PASS_BY_REFERENCE tilepro_pass_by_reference | |
4978 | ||
4979 | #undef TARGET_RETURN_IN_MEMORY | |
4980 | #define TARGET_RETURN_IN_MEMORY tilepro_return_in_memory | |
4981 | ||
4982 | #undef TARGET_FUNCTION_ARG_BOUNDARY | |
4983 | #define TARGET_FUNCTION_ARG_BOUNDARY tilepro_function_arg_boundary | |
4984 | ||
4985 | #undef TARGET_FUNCTION_ARG | |
4986 | #define TARGET_FUNCTION_ARG tilepro_function_arg | |
4987 | ||
4988 | #undef TARGET_FUNCTION_ARG_ADVANCE | |
4989 | #define TARGET_FUNCTION_ARG_ADVANCE tilepro_function_arg_advance | |
4990 | ||
4991 | #undef TARGET_FUNCTION_VALUE | |
4992 | #define TARGET_FUNCTION_VALUE tilepro_function_value | |
4993 | ||
4994 | #undef TARGET_LIBCALL_VALUE | |
4995 | #define TARGET_LIBCALL_VALUE tilepro_libcall_value | |
4996 | ||
4997 | #undef TARGET_FUNCTION_VALUE_REGNO_P | |
4998 | #define TARGET_FUNCTION_VALUE_REGNO_P tilepro_function_value_regno_p | |
4999 | ||
5000 | #undef TARGET_PROMOTE_FUNCTION_MODE | |
5001 | #define TARGET_PROMOTE_FUNCTION_MODE \ | |
5002 | default_promote_function_mode_always_promote | |
5003 | ||
5004 | #undef TARGET_PROMOTE_PROTOTYPES | |
5005 | #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_false | |
5006 | ||
5007 | #undef TARGET_BUILD_BUILTIN_VA_LIST | |
5008 | #define TARGET_BUILD_BUILTIN_VA_LIST tilepro_build_builtin_va_list | |
5009 | ||
5010 | #undef TARGET_EXPAND_BUILTIN_VA_START | |
5011 | #define TARGET_EXPAND_BUILTIN_VA_START tilepro_va_start | |
5012 | ||
5013 | #undef TARGET_SETUP_INCOMING_VARARGS | |
5014 | #define TARGET_SETUP_INCOMING_VARARGS tilepro_setup_incoming_varargs | |
5015 | ||
5016 | #undef TARGET_GIMPLIFY_VA_ARG_EXPR | |
5017 | #define TARGET_GIMPLIFY_VA_ARG_EXPR tilepro_gimplify_va_arg_expr | |
5018 | ||
5019 | #undef TARGET_RTX_COSTS | |
5020 | #define TARGET_RTX_COSTS tilepro_rtx_costs | |
5021 | ||
5022 | /* Limit to what we can reach in one addli. */ | |
5023 | #undef TARGET_MIN_ANCHOR_OFFSET | |
5024 | #define TARGET_MIN_ANCHOR_OFFSET -32768 | |
5025 | #undef TARGET_MAX_ANCHOR_OFFSET | |
5026 | #define TARGET_MAX_ANCHOR_OFFSET 32767 | |
5027 | ||
5028 | #undef TARGET_LEGITIMATE_CONSTANT_P | |
5029 | #define TARGET_LEGITIMATE_CONSTANT_P tilepro_legitimate_constant_p | |
5030 | ||
5031 | #undef TARGET_LEGITIMATE_ADDRESS_P | |
5032 | #define TARGET_LEGITIMATE_ADDRESS_P tilepro_legitimate_address_p | |
5033 | ||
5034 | #undef TARGET_LEGITIMIZE_ADDRESS | |
5035 | #define TARGET_LEGITIMIZE_ADDRESS tilepro_legitimize_address | |
5036 | ||
5037 | #undef TARGET_DELEGITIMIZE_ADDRESS | |
5038 | #define TARGET_DELEGITIMIZE_ADDRESS tilepro_delegitimize_address | |
5039 | ||
5040 | #undef TARGET_INIT_BUILTINS | |
5041 | #define TARGET_INIT_BUILTINS tilepro_init_builtins | |
5042 | ||
5043 | #undef TARGET_BUILTIN_DECL | |
5044 | #define TARGET_BUILTIN_DECL tilepro_builtin_decl | |
5045 | ||
5046 | #undef TARGET_EXPAND_BUILTIN | |
5047 | #define TARGET_EXPAND_BUILTIN tilepro_expand_builtin | |
5048 | ||
5049 | #undef TARGET_CONDITIONAL_REGISTER_USAGE | |
5050 | #define TARGET_CONDITIONAL_REGISTER_USAGE tilepro_conditional_register_usage | |
5051 | ||
5052 | #undef TARGET_FRAME_POINTER_REQUIRED | |
5053 | #define TARGET_FRAME_POINTER_REQUIRED tilepro_frame_pointer_required | |
5054 | ||
5055 | #undef TARGET_DELAY_SCHED2 | |
5056 | #define TARGET_DELAY_SCHED2 true | |
5057 | ||
5058 | #undef TARGET_DELAY_VARTRACK | |
5059 | #define TARGET_DELAY_VARTRACK true | |
5060 | ||
5061 | #undef TARGET_SCHED_ISSUE_RATE | |
5062 | #define TARGET_SCHED_ISSUE_RATE tilepro_issue_rate | |
5063 | ||
5064 | #undef TARGET_SCHED_ADJUST_COST | |
5065 | #define TARGET_SCHED_ADJUST_COST tilepro_sched_adjust_cost | |
5066 | ||
5067 | #undef TARGET_MACHINE_DEPENDENT_REORG | |
5068 | #define TARGET_MACHINE_DEPENDENT_REORG tilepro_reorg | |
5069 | ||
5070 | #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK | |
5071 | #define TARGET_ASM_CAN_OUTPUT_MI_THUNK \ | |
5072 | hook_bool_const_tree_hwi_hwi_const_tree_true | |
5073 | ||
5074 | #undef TARGET_ASM_OUTPUT_MI_THUNK | |
5075 | #define TARGET_ASM_OUTPUT_MI_THUNK tilepro_asm_output_mi_thunk | |
5076 | ||
5077 | #undef TARGET_ASM_TRAMPOLINE_TEMPLATE | |
5078 | #define TARGET_ASM_TRAMPOLINE_TEMPLATE tilepro_asm_trampoline_template | |
5079 | ||
5080 | #undef TARGET_TRAMPOLINE_INIT | |
5081 | #define TARGET_TRAMPOLINE_INIT tilepro_trampoline_init | |
5082 | ||
5083 | #undef TARGET_PRINT_OPERAND | |
5084 | #define TARGET_PRINT_OPERAND tilepro_print_operand | |
5085 | ||
5086 | #undef TARGET_PRINT_OPERAND_ADDRESS | |
5087 | #define TARGET_PRINT_OPERAND_ADDRESS tilepro_print_operand_address | |
5088 | ||
5089 | #undef TARGET_ASM_FILE_END | |
5090 | #define TARGET_ASM_FILE_END tilepro_file_end | |
5091 | ||
5f35dd0e | 5092 | #undef TARGET_CAN_USE_DOLOOP_P |
5093 | #define TARGET_CAN_USE_DOLOOP_P can_use_doloop_if_innermost | |
7ce78e23 | 5094 | |
5095 | struct gcc_target targetm = TARGET_INITIALIZER; | |
5096 | ||
5097 | #include "gt-tilepro.h" |