1 /* Subroutines used for code generation on the Synopsys DesignWare ARC cpu. 2 Copyright (C) 1994-2018 Free Software Foundation, Inc. 3 4 Sources derived from work done by Sankhya Technologies (www.sankhya.com) on 5 behalf of Synopsys Inc. 6 7 Position Independent Code support added,Code cleaned up, 8 Comments and Support For ARC700 instructions added by 9 Saurabh Verma (saurabh.verma@codito.com) 10 Ramana Radhakrishnan(ramana.radhakrishnan@codito.com) 11 12 Fixing ABI inconsistencies, optimizations for ARC600 / ARC700 pipelines, 13 profiling support added by Joern Rennecke <joern.rennecke@embecosm.com> 14 15 This file is part of GCC. 16 17 GCC is free software; you can redistribute it and/or modify 18 it under the terms of the GNU General Public License as published by 19 the Free Software Foundation; either version 3, or (at your option) 20 any later version. 21 22 GCC is distributed in the hope that it will be useful, 23 but WITHOUT ANY WARRANTY; without even the implied warranty of 24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 GNU General Public License for more details. 26 27 You should have received a copy of the GNU General Public License 28 along with GCC; see the file COPYING3. If not see 29 <http://www.gnu.org/licenses/>. */ 30 31 #define IN_TARGET_CODE 1 32 33 #include "config.h" 34 #include "system.h" 35 #include "coretypes.h" 36 #include "memmodel.h" 37 #include "backend.h" 38 #include "target.h" 39 #include "rtl.h" 40 #include "tree.h" 41 #include "cfghooks.h" 42 #include "df.h" 43 #include "tm_p.h" 44 #include "stringpool.h" 45 #include "attribs.h" 46 #include "optabs.h" 47 #include "regs.h" 48 #include "emit-rtl.h" 49 #include "recog.h" 50 #include "diagnostic.h" 51 #include "fold-const.h" 52 #include "varasm.h" 53 #include "stor-layout.h" 54 #include "calls.h" 55 #include "output.h" 56 #include "insn-attr.h" 57 #include "flags.h" 58 #include "explow.h" 59 #include "expr.h" 60 #include "langhooks.h" 61 #include "tm-constrs.h" 62 #include "reload.h" /* For operands_match_p */ 63 #include "cfgrtl.h" 64 #include "tree-pass.h" 65 #include "context.h" 66 #include "builtins.h" 67 #include "rtl-iter.h" 68 #include "alias.h" 69 #include "opts.h" 70 #include "hw-doloop.h" 71 72 /* Which cpu we're compiling for (ARC600, ARC601, ARC700). */ 73 static char arc_cpu_name[10] = ""; 74 static const char *arc_cpu_string = arc_cpu_name; 75 76 typedef struct GTY (()) _arc_jli_section 77 { 78 const char *name; 79 struct _arc_jli_section *next; 80 } arc_jli_section; 81 82 static arc_jli_section *arc_jli_sections = NULL; 83 84 /* Track which regs are set fixed/call saved/call used from commnad line. */ 85 HARD_REG_SET overrideregs; 86 87 /* Maximum size of a loop. */ 88 #define ARC_MAX_LOOP_LENGTH 4095 89 90 /* ??? Loads can handle any constant, stores can only handle small ones. */ 91 /* OTOH, LIMMs cost extra, so their usefulness is limited. */ 92 #define RTX_OK_FOR_OFFSET_P(MODE, X) \ 93 (GET_CODE (X) == CONST_INT \ 94 && SMALL_INT_RANGE (INTVAL (X), (GET_MODE_SIZE (MODE) - 1) & -4, \ 95 (INTVAL (X) & (GET_MODE_SIZE (MODE) - 1) & 3 \ 96 ? 0 \ 97 : -(-GET_MODE_SIZE (MODE) | -4) >> 1))) 98 99 #define LEGITIMATE_SMALL_DATA_OFFSET_P(X) \ 100 (GET_CODE (X) == CONST \ 101 && GET_CODE (XEXP ((X), 0)) == PLUS \ 102 && GET_CODE (XEXP (XEXP ((X), 0), 0)) == SYMBOL_REF \ 103 && SYMBOL_REF_SMALL_P (XEXP (XEXP ((X), 0), 0)) \ 104 && GET_CODE (XEXP(XEXP ((X), 0), 1)) == CONST_INT \ 105 && INTVAL (XEXP (XEXP ((X), 0), 1)) <= g_switch_value) 106 107 #define LEGITIMATE_SMALL_DATA_ADDRESS_P(X) \ 108 (GET_CODE (X) == PLUS \ 109 && REG_P (XEXP ((X), 0)) \ 110 && REGNO (XEXP ((X), 0)) == SDATA_BASE_REGNUM \ 111 && ((GET_CODE (XEXP ((X), 1)) == SYMBOL_REF \ 112 && SYMBOL_REF_SMALL_P (XEXP ((X), 1))) \ 113 || LEGITIMATE_SMALL_DATA_OFFSET_P (XEXP ((X), 1)))) 114 115 /* Array of valid operand punctuation characters. */ 116 char arc_punct_chars[256]; 117 118 /* State used by arc_ccfsm_advance to implement conditional execution. */ 119 struct GTY (()) arc_ccfsm 120 { 121 int state; 122 int cc; 123 rtx cond; 124 rtx_insn *target_insn; 125 int target_label; 126 }; 127 128 /* Status of the IRQ_CTRL_AUX register. */ 129 typedef struct irq_ctrl_saved_t 130 { 131 /* Last register number used by IRQ_CTRL_SAVED aux_reg. */ 132 short irq_save_last_reg; 133 /* True if BLINK is automatically saved. */ 134 bool irq_save_blink; 135 /* True if LPCOUNT is automatically saved. */ 136 bool irq_save_lpcount; 137 } irq_ctrl_saved_t; 138 static irq_ctrl_saved_t irq_ctrl_saved; 139 140 #define ARC_AUTOBLINK_IRQ_P(FNTYPE) \ 141 ((ARC_INTERRUPT_P (FNTYPE) \ 142 && irq_ctrl_saved.irq_save_blink) \ 143 || (ARC_FAST_INTERRUPT_P (FNTYPE) \ 144 && rgf_banked_register_count > 8)) 145 146 #define ARC_AUTOFP_IRQ_P(FNTYPE) \ 147 ((ARC_INTERRUPT_P (FNTYPE) \ 148 && (irq_ctrl_saved.irq_save_last_reg > 26)) \ 149 || (ARC_FAST_INTERRUPT_P (FNTYPE) \ 150 && rgf_banked_register_count > 8)) 151 152 #define ARC_AUTO_IRQ_P(FNTYPE) \ 153 (ARC_INTERRUPT_P (FNTYPE) && !ARC_FAST_INTERRUPT_P (FNTYPE) \ 154 && (irq_ctrl_saved.irq_save_blink \ 155 || (irq_ctrl_saved.irq_save_last_reg >= 0))) 156 157 /* Number of registers in second bank for FIRQ support. */ 158 static int rgf_banked_register_count; 159 160 #define arc_ccfsm_current cfun->machine->ccfsm_current 161 162 #define ARC_CCFSM_BRANCH_DELETED_P(STATE) \ 163 ((STATE)->state == 1 || (STATE)->state == 2) 164 165 /* Indicate we're conditionalizing insns now. */ 166 #define ARC_CCFSM_RECORD_BRANCH_DELETED(STATE) \ 167 ((STATE)->state += 2) 168 169 #define ARC_CCFSM_COND_EXEC_P(STATE) \ 170 ((STATE)->state == 3 || (STATE)->state == 4 || (STATE)->state == 5 \ 171 || current_insn_predicate) 172 173 /* Check if INSN has a 16 bit opcode considering struct arc_ccfsm *STATE. */ 174 #define CCFSM_ISCOMPACT(INSN,STATE) \ 175 (ARC_CCFSM_COND_EXEC_P (STATE) \ 176 ? (get_attr_iscompact (INSN) == ISCOMPACT_TRUE \ 177 || get_attr_iscompact (INSN) == ISCOMPACT_TRUE_LIMM) \ 178 : get_attr_iscompact (INSN) != ISCOMPACT_FALSE) 179 180 /* Likewise, but also consider that INSN might be in a delay slot of JUMP. */ 181 #define CCFSM_DBR_ISCOMPACT(INSN,JUMP,STATE) \ 182 ((ARC_CCFSM_COND_EXEC_P (STATE) \ 183 || (JUMP_P (JUMP) \ 184 && INSN_ANNULLED_BRANCH_P (JUMP) \ 185 && (TARGET_AT_DBR_CONDEXEC || INSN_FROM_TARGET_P (INSN)))) \ 186 ? (get_attr_iscompact (INSN) == ISCOMPACT_TRUE \ 187 || get_attr_iscompact (INSN) == ISCOMPACT_TRUE_LIMM) \ 188 : get_attr_iscompact (INSN) != ISCOMPACT_FALSE) 189 190 /* The maximum number of insns skipped which will be conditionalised if 191 possible. */ 192 /* When optimizing for speed: 193 Let p be the probability that the potentially skipped insns need to 194 be executed, pn the cost of a correctly predicted non-taken branch, 195 mt the cost of a mis/non-predicted taken branch, 196 mn mispredicted non-taken, pt correctly predicted taken ; 197 costs expressed in numbers of instructions like the ones considered 198 skipping. 199 Unfortunately we don't have a measure of predictability - this 200 is linked to probability only in that in the no-eviction-scenario 201 there is a lower bound 1 - 2 * min (p, 1-p), and a somewhat larger 202 value that can be assumed *if* the distribution is perfectly random. 203 A predictability of 1 is perfectly plausible not matter what p is, 204 because the decision could be dependent on an invocation parameter 205 of the program. 206 For large p, we want MAX_INSNS_SKIPPED == pn/(1-p) + mt - pn 207 For small p, we want MAX_INSNS_SKIPPED == pt 208 209 When optimizing for size: 210 We want to skip insn unless we could use 16 opcodes for the 211 non-conditionalized insn to balance the branch length or more. 212 Performance can be tie-breaker. */ 213 /* If the potentially-skipped insns are likely to be executed, we'll 214 generally save one non-taken branch 215 o 216 this to be no less than the 1/p */ 217 #define MAX_INSNS_SKIPPED 3 218 219 /* A nop is needed between a 4 byte insn that sets the condition codes and 220 a branch that uses them (the same isn't true for an 8 byte insn that sets 221 the condition codes). Set by arc_ccfsm_advance. Used by 222 arc_print_operand. */ 223 224 static int get_arc_condition_code (rtx); 225 226 static tree arc_handle_interrupt_attribute (tree *, tree, tree, int, bool *); 227 static tree arc_handle_fndecl_attribute (tree *, tree, tree, int, bool *); 228 static tree arc_handle_jli_attribute (tree *, tree, tree, int, bool *); 229 static tree arc_handle_secure_attribute (tree *, tree, tree, int, bool *); 230 static tree arc_handle_uncached_attribute (tree *, tree, tree, int, bool *); 231 static tree arc_handle_aux_attribute (tree *, tree, tree, int, bool *); 232 233 /* Initialized arc_attribute_table to NULL since arc doesnot have any 234 machine specific supported attributes. */ 235 const struct attribute_spec arc_attribute_table[] = 236 { 237 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, 238 affects_type_identity, handler, exclude } */ 239 { "interrupt", 1, 1, true, false, false, true, 240 arc_handle_interrupt_attribute, NULL }, 241 /* Function calls made to this symbol must be done indirectly, because 242 it may lie outside of the 21/25 bit addressing range of a normal function 243 call. */ 244 { "long_call", 0, 0, false, true, true, false, NULL, NULL }, 245 /* Whereas these functions are always known to reside within the 25 bit 246 addressing range of unconditionalized bl. */ 247 { "medium_call", 0, 0, false, true, true, false, NULL, NULL }, 248 /* And these functions are always known to reside within the 21 bit 249 addressing range of blcc. */ 250 { "short_call", 0, 0, false, true, true, false, NULL, NULL }, 251 /* Function which are not having the prologue and epilogue generated 252 by the compiler. */ 253 { "naked", 0, 0, true, false, false, false, arc_handle_fndecl_attribute, 254 NULL }, 255 /* Functions calls made using jli instruction. The pointer in JLI 256 table is found latter. */ 257 { "jli_always", 0, 0, false, true, true, false, NULL, NULL }, 258 /* Functions calls made using jli instruction. The pointer in JLI 259 table is given as input parameter. */ 260 { "jli_fixed", 1, 1, false, true, true, false, arc_handle_jli_attribute, 261 NULL }, 262 /* Call a function using secure-mode. */ 263 { "secure_call", 1, 1, false, true, true, false, arc_handle_secure_attribute, 264 NULL }, 265 /* Bypass caches using .di flag. */ 266 { "uncached", 0, 0, false, true, false, false, arc_handle_uncached_attribute, 267 NULL }, 268 { "aux", 0, 1, true, false, false, false, arc_handle_aux_attribute, NULL }, 269 { NULL, 0, 0, false, false, false, false, NULL, NULL } 270 }; 271 static int arc_comp_type_attributes (const_tree, const_tree); 272 static void arc_file_start (void); 273 static void arc_internal_label (FILE *, const char *, unsigned long); 274 static void arc_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, 275 tree); 276 static int arc_address_cost (rtx, machine_mode, addr_space_t, bool); 277 static void arc_encode_section_info (tree decl, rtx rtl, int first); 278 279 static void arc_init_builtins (void); 280 static rtx arc_expand_builtin (tree, rtx, rtx, machine_mode, int); 281 282 static int branch_dest (rtx); 283 284 static void arc_output_pic_addr_const (FILE *, rtx, int); 285 static bool arc_function_ok_for_sibcall (tree, tree); 286 static rtx arc_function_value (const_tree, const_tree, bool); 287 const char * output_shift (rtx *); 288 static void arc_reorg (void); 289 static bool arc_in_small_data_p (const_tree); 290 291 static void arc_init_reg_tables (void); 292 static bool arc_return_in_memory (const_tree, const_tree); 293 static bool arc_vector_mode_supported_p (machine_mode); 294 295 static bool arc_can_use_doloop_p (const widest_int &, const widest_int &, 296 unsigned int, bool); 297 static const char *arc_invalid_within_doloop (const rtx_insn *); 298 299 static void output_short_suffix (FILE *file); 300 301 static bool arc_frame_pointer_required (void); 302 303 static bool arc_use_by_pieces_infrastructure_p (unsigned HOST_WIDE_INT, 304 unsigned int, 305 enum by_pieces_operation op, 306 bool); 307 308 /* Globally visible information about currently selected cpu. */ 309 const arc_cpu_t *arc_selected_cpu; 310 311 static bool 312 legitimate_scaled_address_p (machine_mode mode, rtx op, bool strict) 313 { 314 if (GET_CODE (op) != PLUS) 315 return false; 316 317 if (GET_CODE (XEXP (op, 0)) != MULT) 318 return false; 319 320 /* Check multiplication operands. */ 321 if (!RTX_OK_FOR_INDEX_P (XEXP (XEXP (op, 0), 0), strict)) 322 return false; 323 324 if (!CONST_INT_P (XEXP (XEXP (op, 0), 1))) 325 return false; 326 327 switch (GET_MODE_SIZE (mode)) 328 { 329 case 2: 330 if (INTVAL (XEXP (XEXP (op, 0), 1)) != 2) 331 return false; 332 break; 333 case 8: 334 if (!TARGET_LL64) 335 return false; 336 /* Fall through. */ 337 case 4: 338 if (INTVAL (XEXP (XEXP (op, 0), 1)) != 4) 339 return false; 340 /* Fall through. */ 341 default: 342 return false; 343 } 344 345 /* Check the base. */ 346 if (RTX_OK_FOR_BASE_P (XEXP (op, 1), (strict))) 347 return true; 348 349 if (flag_pic) 350 { 351 if (CONST_INT_P (XEXP (op, 1))) 352 return true; 353 return false; 354 } 355 if (CONSTANT_P (XEXP (op, 1))) 356 { 357 /* Scalled addresses for sdata is done other places. */ 358 if (GET_CODE (XEXP (op, 1)) == SYMBOL_REF 359 && SYMBOL_REF_SMALL_P (XEXP (op, 1))) 360 return false; 361 return true; 362 } 363 364 return false; 365 } 366 367 /* Check for constructions like REG + OFFS, where OFFS can be a 368 register, an immediate or an long immediate. */ 369 370 static bool 371 legitimate_offset_address_p (machine_mode mode, rtx x, bool index, bool strict) 372 { 373 if (GET_CODE (x) != PLUS) 374 return false; 375 376 if (!RTX_OK_FOR_BASE_P (XEXP (x, 0), (strict))) 377 return false; 378 379 /* Check for: [Rx + small offset] or [Rx + Ry]. */ 380 if (((index && RTX_OK_FOR_INDEX_P (XEXP (x, 1), (strict)) 381 && GET_MODE_SIZE ((mode)) <= 4) 382 || RTX_OK_FOR_OFFSET_P (mode, XEXP (x, 1)))) 383 return true; 384 385 /* Check for [Rx + symbol]. */ 386 if (!flag_pic 387 && (GET_CODE (XEXP (x, 1)) == SYMBOL_REF) 388 /* Avoid this type of address for double or larger modes. */ 389 && (GET_MODE_SIZE (mode) <= 4) 390 /* Avoid small data which ends in something like GP + 391 symb@sda. */ 392 && (!SYMBOL_REF_SMALL_P (XEXP (x, 1)))) 393 return true; 394 395 return false; 396 } 397 398 /* Implements target hook vector_mode_supported_p. */ 399 400 static bool 401 arc_vector_mode_supported_p (machine_mode mode) 402 { 403 switch (mode) 404 { 405 case E_V2HImode: 406 return TARGET_PLUS_DMPY; 407 case E_V4HImode: 408 case E_V2SImode: 409 return TARGET_PLUS_QMACW; 410 case E_V4SImode: 411 case E_V8HImode: 412 return TARGET_SIMD_SET; 413 414 default: 415 return false; 416 } 417 } 418 419 /* Implements target hook TARGET_VECTORIZE_PREFERRED_SIMD_MODE. */ 420 421 static machine_mode 422 arc_preferred_simd_mode (scalar_mode mode) 423 { 424 switch (mode) 425 { 426 case E_HImode: 427 return TARGET_PLUS_QMACW ? V4HImode : V2HImode; 428 case E_SImode: 429 return V2SImode; 430 431 default: 432 return word_mode; 433 } 434 } 435 436 /* Implements target hook 437 TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES. */ 438 439 static void 440 arc_autovectorize_vector_sizes (vector_sizes *sizes) 441 { 442 if (TARGET_PLUS_QMACW) 443 { 444 sizes->quick_push (8); 445 sizes->quick_push (4); 446 } 447 } 448 449 /* TARGET_PRESERVE_RELOAD_P is still awaiting patch re-evaluation / review. */ 450 static bool arc_preserve_reload_p (rtx in) ATTRIBUTE_UNUSED; 451 static rtx arc_delegitimize_address (rtx); 452 static bool arc_can_follow_jump (const rtx_insn *follower, 453 const rtx_insn *followee); 454 455 static rtx frame_insn (rtx); 456 static void arc_function_arg_advance (cumulative_args_t, machine_mode, 457 const_tree, bool); 458 static rtx arc_legitimize_address_0 (rtx, rtx, machine_mode mode); 459 460 /* initialize the GCC target structure. */ 461 #undef TARGET_COMP_TYPE_ATTRIBUTES 462 #define TARGET_COMP_TYPE_ATTRIBUTES arc_comp_type_attributes 463 #undef TARGET_ASM_FILE_START 464 #define TARGET_ASM_FILE_START arc_file_start 465 #undef TARGET_ATTRIBUTE_TABLE 466 #define TARGET_ATTRIBUTE_TABLE arc_attribute_table 467 #undef TARGET_ASM_INTERNAL_LABEL 468 #define TARGET_ASM_INTERNAL_LABEL arc_internal_label 469 #undef TARGET_RTX_COSTS 470 #define TARGET_RTX_COSTS arc_rtx_costs 471 #undef TARGET_ADDRESS_COST 472 #define TARGET_ADDRESS_COST arc_address_cost 473 474 #undef TARGET_ENCODE_SECTION_INFO 475 #define TARGET_ENCODE_SECTION_INFO arc_encode_section_info 476 477 #undef TARGET_CANNOT_FORCE_CONST_MEM 478 #define TARGET_CANNOT_FORCE_CONST_MEM arc_cannot_force_const_mem 479 480 #undef TARGET_INIT_BUILTINS 481 #define TARGET_INIT_BUILTINS arc_init_builtins 482 483 #undef TARGET_EXPAND_BUILTIN 484 #define TARGET_EXPAND_BUILTIN arc_expand_builtin 485 486 #undef TARGET_BUILTIN_DECL 487 #define TARGET_BUILTIN_DECL arc_builtin_decl 488 489 #undef TARGET_ASM_OUTPUT_MI_THUNK 490 #define TARGET_ASM_OUTPUT_MI_THUNK arc_output_mi_thunk 491 492 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK 493 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true 494 495 #undef TARGET_FUNCTION_OK_FOR_SIBCALL 496 #define TARGET_FUNCTION_OK_FOR_SIBCALL arc_function_ok_for_sibcall 497 498 #undef TARGET_MACHINE_DEPENDENT_REORG 499 #define TARGET_MACHINE_DEPENDENT_REORG arc_reorg 500 501 #undef TARGET_IN_SMALL_DATA_P 502 #define TARGET_IN_SMALL_DATA_P arc_in_small_data_p 503 504 #undef TARGET_PROMOTE_FUNCTION_MODE 505 #define TARGET_PROMOTE_FUNCTION_MODE \ 506 default_promote_function_mode_always_promote 507 508 #undef TARGET_PROMOTE_PROTOTYPES 509 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true 510 511 #undef TARGET_RETURN_IN_MEMORY 512 #define TARGET_RETURN_IN_MEMORY arc_return_in_memory 513 #undef TARGET_PASS_BY_REFERENCE 514 #define TARGET_PASS_BY_REFERENCE arc_pass_by_reference 515 516 #undef TARGET_SETUP_INCOMING_VARARGS 517 #define TARGET_SETUP_INCOMING_VARARGS arc_setup_incoming_varargs 518 519 #undef TARGET_ARG_PARTIAL_BYTES 520 #define TARGET_ARG_PARTIAL_BYTES arc_arg_partial_bytes 521 522 #undef TARGET_MUST_PASS_IN_STACK 523 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size 524 525 #undef TARGET_FUNCTION_VALUE 526 #define TARGET_FUNCTION_VALUE arc_function_value 527 528 #undef TARGET_SCHED_ADJUST_PRIORITY 529 #define TARGET_SCHED_ADJUST_PRIORITY arc_sched_adjust_priority 530 531 #undef TARGET_VECTOR_MODE_SUPPORTED_P 532 #define TARGET_VECTOR_MODE_SUPPORTED_P arc_vector_mode_supported_p 533 534 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE 535 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE arc_preferred_simd_mode 536 537 #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES 538 #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES arc_autovectorize_vector_sizes 539 540 #undef TARGET_CAN_USE_DOLOOP_P 541 #define TARGET_CAN_USE_DOLOOP_P arc_can_use_doloop_p 542 543 #undef TARGET_INVALID_WITHIN_DOLOOP 544 #define TARGET_INVALID_WITHIN_DOLOOP arc_invalid_within_doloop 545 546 #undef TARGET_PRESERVE_RELOAD_P 547 #define TARGET_PRESERVE_RELOAD_P arc_preserve_reload_p 548 549 #undef TARGET_CAN_FOLLOW_JUMP 550 #define TARGET_CAN_FOLLOW_JUMP arc_can_follow_jump 551 552 #undef TARGET_DELEGITIMIZE_ADDRESS 553 #define TARGET_DELEGITIMIZE_ADDRESS arc_delegitimize_address 554 555 #undef TARGET_USE_BY_PIECES_INFRASTRUCTURE_P 556 #define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P \ 557 arc_use_by_pieces_infrastructure_p 558 559 /* Usually, we will be able to scale anchor offsets. 560 When this fails, we want LEGITIMIZE_ADDRESS to kick in. */ 561 #undef TARGET_MIN_ANCHOR_OFFSET 562 #define TARGET_MIN_ANCHOR_OFFSET (-1024) 563 #undef TARGET_MAX_ANCHOR_OFFSET 564 #define TARGET_MAX_ANCHOR_OFFSET (1020) 565 566 #undef TARGET_SECONDARY_RELOAD 567 #define TARGET_SECONDARY_RELOAD arc_secondary_reload 568 569 #define TARGET_OPTION_OVERRIDE arc_override_options 570 571 #define TARGET_CONDITIONAL_REGISTER_USAGE arc_conditional_register_usage 572 573 #define TARGET_TRAMPOLINE_INIT arc_initialize_trampoline 574 575 #define TARGET_CAN_ELIMINATE arc_can_eliminate 576 577 #define TARGET_FRAME_POINTER_REQUIRED arc_frame_pointer_required 578 579 #define TARGET_FUNCTION_ARG arc_function_arg 580 581 #define TARGET_FUNCTION_ARG_ADVANCE arc_function_arg_advance 582 583 #define TARGET_LEGITIMATE_CONSTANT_P arc_legitimate_constant_p 584 585 #define TARGET_LEGITIMATE_ADDRESS_P arc_legitimate_address_p 586 587 #define TARGET_MODE_DEPENDENT_ADDRESS_P arc_mode_dependent_address_p 588 589 #define TARGET_LEGITIMIZE_ADDRESS arc_legitimize_address 590 591 #undef TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P 592 #define TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P \ 593 arc_no_speculation_in_delay_slots_p 594 595 #undef TARGET_LRA_P 596 #define TARGET_LRA_P arc_lra_p 597 #define TARGET_REGISTER_PRIORITY arc_register_priority 598 /* Stores with scaled offsets have different displacement ranges. */ 599 #define TARGET_DIFFERENT_ADDR_DISPLACEMENT_P hook_bool_void_true 600 #define TARGET_SPILL_CLASS arc_spill_class 601 602 #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS 603 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arc_allocate_stack_slots_for_args 604 605 #undef TARGET_WARN_FUNC_RETURN 606 #define TARGET_WARN_FUNC_RETURN arc_warn_func_return 607 608 #include "target-def.h" 609 610 #undef TARGET_ASM_ALIGNED_HI_OP 611 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t" 612 #undef TARGET_ASM_ALIGNED_SI_OP 613 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t" 614 615 #ifdef HAVE_AS_TLS 616 #undef TARGET_HAVE_TLS 617 #define TARGET_HAVE_TLS HAVE_AS_TLS 618 #endif 619 620 #undef TARGET_DWARF_REGISTER_SPAN 621 #define TARGET_DWARF_REGISTER_SPAN arc_dwarf_register_span 622 623 #undef TARGET_HARD_REGNO_NREGS 624 #define TARGET_HARD_REGNO_NREGS arc_hard_regno_nregs 625 #undef TARGET_HARD_REGNO_MODE_OK 626 #define TARGET_HARD_REGNO_MODE_OK arc_hard_regno_mode_ok 627 628 #undef TARGET_MODES_TIEABLE_P 629 #define TARGET_MODES_TIEABLE_P arc_modes_tieable_p 630 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE 631 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE arc_builtin_setjmp_frame_value 632 633 /* Try to keep the (mov:DF _, reg) as early as possible so 634 that the d<add/sub/mul>h-lr insns appear together and can 635 use the peephole2 pattern. */ 636 637 static int 638 arc_sched_adjust_priority (rtx_insn *insn, int priority) 639 { 640 rtx set = single_set (insn); 641 if (set 642 && GET_MODE (SET_SRC(set)) == DFmode 643 && GET_CODE (SET_SRC(set)) == REG) 644 { 645 /* Incrementing priority by 20 (empirically derived). */ 646 return priority + 20; 647 } 648 649 return priority; 650 } 651 652 /* For ARC base register + offset addressing, the validity of the 653 address is mode-dependent for most of the offset range, as the 654 offset can be scaled by the access size. 655 We don't expose these as mode-dependent addresses in the 656 mode_dependent_address_p target hook, because that would disable 657 lots of optimizations, and most uses of these addresses are for 32 658 or 64 bit accesses anyways, which are fine. 659 However, that leaves some addresses for 8 / 16 bit values not 660 properly reloaded by the generic code, which is why we have to 661 schedule secondary reloads for these. */ 662 663 static reg_class_t 664 arc_secondary_reload (bool in_p, 665 rtx x, 666 reg_class_t cl, 667 machine_mode mode, 668 secondary_reload_info *sri) 669 { 670 enum rtx_code code = GET_CODE (x); 671 672 if (cl == DOUBLE_REGS) 673 return GENERAL_REGS; 674 675 /* The loop counter register can be stored, but not loaded directly. */ 676 if ((cl == LPCOUNT_REG || cl == WRITABLE_CORE_REGS) 677 && in_p && MEM_P (x)) 678 return GENERAL_REGS; 679 680 /* If we have a subreg (reg), where reg is a pseudo (that will end in 681 a memory location), then we may need a scratch register to handle 682 the fp/sp+largeoffset address. */ 683 if (code == SUBREG) 684 { 685 rtx addr = NULL_RTX; 686 x = SUBREG_REG (x); 687 688 if (REG_P (x)) 689 { 690 int regno = REGNO (x); 691 if (regno >= FIRST_PSEUDO_REGISTER) 692 regno = reg_renumber[regno]; 693 694 if (regno != -1) 695 return NO_REGS; 696 697 /* It is a pseudo that ends in a stack location. */ 698 if (reg_equiv_mem (REGNO (x))) 699 { 700 /* Get the equivalent address and check the range of the 701 offset. */ 702 rtx mem = reg_equiv_mem (REGNO (x)); 703 addr = find_replacement (&XEXP (mem, 0)); 704 } 705 } 706 else 707 { 708 gcc_assert (MEM_P (x)); 709 addr = XEXP (x, 0); 710 addr = simplify_rtx (addr); 711 } 712 if (addr && GET_CODE (addr) == PLUS 713 && CONST_INT_P (XEXP (addr, 1)) 714 && (!RTX_OK_FOR_OFFSET_P (mode, XEXP (addr, 1)))) 715 { 716 switch (mode) 717 { 718 case E_QImode: 719 sri->icode = 720 in_p ? CODE_FOR_reload_qi_load : CODE_FOR_reload_qi_store; 721 break; 722 case E_HImode: 723 sri->icode = 724 in_p ? CODE_FOR_reload_hi_load : CODE_FOR_reload_hi_store; 725 break; 726 default: 727 break; 728 } 729 } 730 } 731 return NO_REGS; 732 } 733 734 /* Convert reloads using offsets that are too large to use indirect 735 addressing. */ 736 737 void 738 arc_secondary_reload_conv (rtx reg, rtx mem, rtx scratch, bool store_p) 739 { 740 rtx addr; 741 742 gcc_assert (GET_CODE (mem) == MEM); 743 addr = XEXP (mem, 0); 744 745 /* Large offset: use a move. FIXME: ld ops accepts limms as 746 offsets. Hence, the following move insn is not required. */ 747 emit_move_insn (scratch, addr); 748 mem = replace_equiv_address_nv (mem, scratch); 749 750 /* Now create the move. */ 751 if (store_p) 752 emit_insn (gen_rtx_SET (mem, reg)); 753 else 754 emit_insn (gen_rtx_SET (reg, mem)); 755 756 return; 757 } 758 759 static unsigned arc_ifcvt (void); 760 761 namespace { 762 763 const pass_data pass_data_arc_ifcvt = 764 { 765 RTL_PASS, 766 "arc_ifcvt", /* name */ 767 OPTGROUP_NONE, /* optinfo_flags */ 768 TV_IFCVT2, /* tv_id */ 769 0, /* properties_required */ 770 0, /* properties_provided */ 771 0, /* properties_destroyed */ 772 0, /* todo_flags_start */ 773 TODO_df_finish /* todo_flags_finish */ 774 }; 775 776 class pass_arc_ifcvt : public rtl_opt_pass 777 { 778 public: 779 pass_arc_ifcvt(gcc::context *ctxt) 780 : rtl_opt_pass(pass_data_arc_ifcvt, ctxt) 781 {} 782 783 /* opt_pass methods: */ 784 opt_pass * clone () { return new pass_arc_ifcvt (m_ctxt); } 785 virtual unsigned int execute (function *) { return arc_ifcvt (); } 786 }; 787 788 } // anon namespace 789 790 rtl_opt_pass * 791 make_pass_arc_ifcvt (gcc::context *ctxt) 792 { 793 return new pass_arc_ifcvt (ctxt); 794 } 795 796 static unsigned arc_predicate_delay_insns (void); 797 798 namespace { 799 800 const pass_data pass_data_arc_predicate_delay_insns = 801 { 802 RTL_PASS, 803 "arc_predicate_delay_insns", /* name */ 804 OPTGROUP_NONE, /* optinfo_flags */ 805 TV_IFCVT2, /* tv_id */ 806 0, /* properties_required */ 807 0, /* properties_provided */ 808 0, /* properties_destroyed */ 809 0, /* todo_flags_start */ 810 TODO_df_finish /* todo_flags_finish */ 811 }; 812 813 class pass_arc_predicate_delay_insns : public rtl_opt_pass 814 { 815 public: 816 pass_arc_predicate_delay_insns(gcc::context *ctxt) 817 : rtl_opt_pass(pass_data_arc_predicate_delay_insns, ctxt) 818 {} 819 820 /* opt_pass methods: */ 821 virtual unsigned int execute (function *) 822 { 823 return arc_predicate_delay_insns (); 824 } 825 }; 826 827 } // anon namespace 828 829 rtl_opt_pass * 830 make_pass_arc_predicate_delay_insns (gcc::context *ctxt) 831 { 832 return new pass_arc_predicate_delay_insns (ctxt); 833 } 834 835 /* Called by OVERRIDE_OPTIONS to initialize various things. */ 836 837 static void 838 arc_init (void) 839 { 840 if (TARGET_V2) 841 { 842 /* I have the multiplier, then use it*/ 843 if (TARGET_MPYW || TARGET_MULTI) 844 arc_multcost = COSTS_N_INSNS (1); 845 } 846 /* Note: arc_multcost is only used in rtx_cost if speed is true. */ 847 if (arc_multcost < 0) 848 switch (arc_tune) 849 { 850 case ARC_TUNE_ARC700_4_2_STD: 851 /* latency 7; 852 max throughput (1 multiply + 4 other insns) / 5 cycles. */ 853 arc_multcost = COSTS_N_INSNS (4); 854 if (TARGET_NOMPY_SET) 855 arc_multcost = COSTS_N_INSNS (30); 856 break; 857 case ARC_TUNE_ARC700_4_2_XMAC: 858 /* latency 5; 859 max throughput (1 multiply + 2 other insns) / 3 cycles. */ 860 arc_multcost = COSTS_N_INSNS (3); 861 if (TARGET_NOMPY_SET) 862 arc_multcost = COSTS_N_INSNS (30); 863 break; 864 case ARC_TUNE_ARC600: 865 if (TARGET_MUL64_SET) 866 { 867 arc_multcost = COSTS_N_INSNS (4); 868 break; 869 } 870 /* Fall through. */ 871 default: 872 arc_multcost = COSTS_N_INSNS (30); 873 break; 874 } 875 876 /* MPY instructions valid only for ARC700 or ARCv2. */ 877 if (TARGET_NOMPY_SET && TARGET_ARC600_FAMILY) 878 error ("-mno-mpy supported only for ARC700 or ARCv2"); 879 880 if (!TARGET_DPFP && TARGET_DPFP_DISABLE_LRSR) 881 error ("-mno-dpfp-lrsr supported only with -mdpfp"); 882 883 /* FPX-1. No fast and compact together. */ 884 if ((TARGET_DPFP_FAST_SET && TARGET_DPFP_COMPACT_SET) 885 || (TARGET_SPFP_FAST_SET && TARGET_SPFP_COMPACT_SET)) 886 error ("FPX fast and compact options cannot be specified together"); 887 888 /* FPX-2. No fast-spfp for arc600 or arc601. */ 889 if (TARGET_SPFP_FAST_SET && TARGET_ARC600_FAMILY) 890 error ("-mspfp_fast not available on ARC600 or ARC601"); 891 892 /* FPX-4. No FPX extensions mixed with FPU extensions. */ 893 if ((TARGET_DPFP_FAST_SET || TARGET_DPFP_COMPACT_SET || TARGET_SPFP) 894 && TARGET_HARD_FLOAT) 895 error ("No FPX/FPU mixing allowed"); 896 897 /* Warn for unimplemented PIC in pre-ARC700 cores, and disable flag_pic. */ 898 if (flag_pic && TARGET_ARC600_FAMILY) 899 { 900 warning (DK_WARNING, 901 "PIC is not supported for %s. Generating non-PIC code only..", 902 arc_cpu_string); 903 flag_pic = 0; 904 } 905 906 arc_init_reg_tables (); 907 908 /* Initialize array for PRINT_OPERAND_PUNCT_VALID_P. */ 909 memset (arc_punct_chars, 0, sizeof (arc_punct_chars)); 910 arc_punct_chars['#'] = 1; 911 arc_punct_chars['*'] = 1; 912 arc_punct_chars['?'] = 1; 913 arc_punct_chars['!'] = 1; 914 arc_punct_chars['^'] = 1; 915 arc_punct_chars['&'] = 1; 916 arc_punct_chars['+'] = 1; 917 arc_punct_chars['_'] = 1; 918 919 if (optimize > 1 && !TARGET_NO_COND_EXEC) 920 { 921 /* There are two target-independent ifcvt passes, and arc_reorg may do 922 one or more arc_ifcvt calls. */ 923 opt_pass *pass_arc_ifcvt_4 = make_pass_arc_ifcvt (g); 924 struct register_pass_info arc_ifcvt4_info 925 = { pass_arc_ifcvt_4, "dbr", 1, PASS_POS_INSERT_AFTER }; 926 struct register_pass_info arc_ifcvt5_info 927 = { pass_arc_ifcvt_4->clone (), "shorten", 1, PASS_POS_INSERT_BEFORE }; 928 929 register_pass (&arc_ifcvt4_info); 930 register_pass (&arc_ifcvt5_info); 931 } 932 933 if (flag_delayed_branch) 934 { 935 opt_pass *pass_arc_predicate_delay_insns 936 = make_pass_arc_predicate_delay_insns (g); 937 struct register_pass_info arc_predicate_delay_info 938 = { pass_arc_predicate_delay_insns, "dbr", 1, PASS_POS_INSERT_AFTER }; 939 940 register_pass (&arc_predicate_delay_info); 941 } 942 } 943 944 /* Parse -mirq-ctrl-saved=RegisterRange, blink, lp_copunt. The 945 register range is specified as two registers separated by a dash. 946 It always starts with r0, and its upper limit is fp register. 947 blink and lp_count registers are optional. */ 948 949 static void 950 irq_range (const char *cstr) 951 { 952 int i, first, last, blink, lpcount, xreg; 953 char *str, *dash, *comma; 954 955 i = strlen (cstr); 956 str = (char *) alloca (i + 1); 957 memcpy (str, cstr, i + 1); 958 blink = -1; 959 lpcount = -1; 960 961 dash = strchr (str, '-'); 962 if (!dash) 963 { 964 warning (0, "value of -mirq-ctrl-saved must have form R0-REGx"); 965 return; 966 } 967 *dash = '\0'; 968 969 comma = strchr (dash + 1, ','); 970 if (comma) 971 *comma = '\0'; 972 973 first = decode_reg_name (str); 974 if (first != 0) 975 { 976 warning (0, "first register must be R0"); 977 return; 978 } 979 980 /* At this moment we do not have the register names initialized 981 accordingly. */ 982 if (!strcmp (dash + 1, "ilink")) 983 last = 29; 984 else 985 last = decode_reg_name (dash + 1); 986 987 if (last < 0) 988 { 989 warning (0, "unknown register name: %s", dash + 1); 990 return; 991 } 992 993 if (!(last & 0x01)) 994 { 995 warning (0, "last register name %s must be an odd register", dash + 1); 996 return; 997 } 998 999 *dash = '-'; 1000 1001 if (first > last) 1002 { 1003 warning (0, "%s-%s is an empty range", str, dash + 1); 1004 return; 1005 } 1006 1007 while (comma) 1008 { 1009 *comma = ','; 1010 str = comma + 1; 1011 1012 comma = strchr (str, ','); 1013 if (comma) 1014 *comma = '\0'; 1015 1016 xreg = decode_reg_name (str); 1017 switch (xreg) 1018 { 1019 case 31: 1020 blink = 31; 1021 break; 1022 1023 case 60: 1024 lpcount = 60; 1025 break; 1026 1027 default: 1028 warning (0, "unknown register name: %s", str); 1029 return; 1030 } 1031 } 1032 1033 irq_ctrl_saved.irq_save_last_reg = last; 1034 irq_ctrl_saved.irq_save_blink = (blink == 31) || (last == 31); 1035 irq_ctrl_saved.irq_save_lpcount = (lpcount == 60); 1036 } 1037 1038 /* Parse -mrgf-banked-regs=NUM option string. Valid values for NUM are 4, 1039 8, 16, or 32. */ 1040 1041 static void 1042 parse_mrgf_banked_regs_option (const char *arg) 1043 { 1044 long int val; 1045 char *end_ptr; 1046 1047 errno = 0; 1048 val = strtol (arg, &end_ptr, 10); 1049 if (errno != 0 || *arg == '\0' || *end_ptr != '\0' 1050 || (val != 0 && val != 4 && val != 8 && val != 16 && val != 32)) 1051 { 1052 error ("invalid number in -mrgf-banked-regs=%s " 1053 "valid values are 0, 4, 8, 16, or 32", arg); 1054 return; 1055 } 1056 rgf_banked_register_count = (int) val; 1057 } 1058 1059 /* Check ARC options, generate derived target attributes. */ 1060 1061 static void 1062 arc_override_options (void) 1063 { 1064 unsigned int i; 1065 cl_deferred_option *opt; 1066 vec<cl_deferred_option> *vopt 1067 = (vec<cl_deferred_option> *) arc_deferred_options; 1068 1069 if (arc_cpu == PROCESSOR_NONE) 1070 arc_cpu = TARGET_CPU_DEFAULT; 1071 1072 /* Set the default cpu options. */ 1073 arc_selected_cpu = &arc_cpu_types[(int) arc_cpu]; 1074 1075 /* Set the architectures. */ 1076 switch (arc_selected_cpu->arch_info->arch_id) 1077 { 1078 case BASE_ARCH_em: 1079 arc_cpu_string = "EM"; 1080 break; 1081 case BASE_ARCH_hs: 1082 arc_cpu_string = "HS"; 1083 break; 1084 case BASE_ARCH_700: 1085 if (arc_selected_cpu->processor == PROCESSOR_nps400) 1086 arc_cpu_string = "NPS400"; 1087 else 1088 arc_cpu_string = "ARC700"; 1089 break; 1090 case BASE_ARCH_6xx: 1091 arc_cpu_string = "ARC600"; 1092 break; 1093 default: 1094 gcc_unreachable (); 1095 } 1096 1097 irq_ctrl_saved.irq_save_last_reg = -1; 1098 irq_ctrl_saved.irq_save_blink = false; 1099 irq_ctrl_saved.irq_save_lpcount = false; 1100 1101 rgf_banked_register_count = 0; 1102 1103 /* Handle the deferred options. */ 1104 if (vopt) 1105 FOR_EACH_VEC_ELT (*vopt, i, opt) 1106 { 1107 switch (opt->opt_index) 1108 { 1109 case OPT_mirq_ctrl_saved_: 1110 if (TARGET_V2) 1111 irq_range (opt->arg); 1112 else 1113 warning (0, "option -mirq-ctrl-saved valid only for ARC v2 processors"); 1114 break; 1115 1116 case OPT_mrgf_banked_regs_: 1117 if (TARGET_V2) 1118 parse_mrgf_banked_regs_option (opt->arg); 1119 else 1120 warning (0, "option -mrgf-banked-regs valid only for ARC v2 processors"); 1121 break; 1122 1123 default: 1124 gcc_unreachable(); 1125 } 1126 } 1127 1128 CLEAR_HARD_REG_SET (overrideregs); 1129 if (common_deferred_options) 1130 { 1131 vec<cl_deferred_option> v = 1132 *((vec<cl_deferred_option> *) common_deferred_options); 1133 int reg, nregs, j; 1134 1135 FOR_EACH_VEC_ELT (v, i, opt) 1136 { 1137 switch (opt->opt_index) 1138 { 1139 case OPT_ffixed_: 1140 case OPT_fcall_used_: 1141 case OPT_fcall_saved_: 1142 if ((reg = decode_reg_name_and_count (opt->arg, &nregs)) >= 0) 1143 for (j = reg; j < reg + nregs; j++) 1144 SET_HARD_REG_BIT (overrideregs, j); 1145 break; 1146 default: 1147 break; 1148 } 1149 } 1150 } 1151 1152 /* Set cpu flags accordingly to architecture/selected cpu. The cpu 1153 specific flags are set in arc-common.c. The architecture forces 1154 the default hardware configurations in, regardless what command 1155 line options are saying. The CPU optional hw options can be 1156 turned on or off. */ 1157 #define ARC_OPT(NAME, CODE, MASK, DOC) \ 1158 do { \ 1159 if ((arc_selected_cpu->flags & CODE) \ 1160 && ((target_flags_explicit & MASK) == 0)) \ 1161 target_flags |= MASK; \ 1162 if (arc_selected_cpu->arch_info->dflags & CODE) \ 1163 target_flags |= MASK; \ 1164 } while (0); 1165 #define ARC_OPTX(NAME, CODE, VAR, VAL, DOC) \ 1166 do { \ 1167 if ((arc_selected_cpu->flags & CODE) \ 1168 && (VAR == DEFAULT_##VAR)) \ 1169 VAR = VAL; \ 1170 if (arc_selected_cpu->arch_info->dflags & CODE) \ 1171 VAR = VAL; \ 1172 } while (0); 1173 1174 #include "arc-options.def" 1175 1176 #undef ARC_OPTX 1177 #undef ARC_OPT 1178 1179 /* Check options against architecture options. Throw an error if 1180 option is not allowed. */ 1181 #define ARC_OPTX(NAME, CODE, VAR, VAL, DOC) \ 1182 do { \ 1183 if ((VAR == VAL) \ 1184 && (!(arc_selected_cpu->arch_info->flags & CODE))) \ 1185 { \ 1186 error ("%s is not available for %s architecture", \ 1187 DOC, arc_selected_cpu->arch_info->name); \ 1188 } \ 1189 } while (0); 1190 #define ARC_OPT(NAME, CODE, MASK, DOC) \ 1191 do { \ 1192 if ((target_flags & MASK) \ 1193 && (!(arc_selected_cpu->arch_info->flags & CODE))) \ 1194 error ("%s is not available for %s architecture", \ 1195 DOC, arc_selected_cpu->arch_info->name); \ 1196 } while (0); 1197 1198 #include "arc-options.def" 1199 1200 #undef ARC_OPTX 1201 #undef ARC_OPT 1202 1203 /* Set Tune option. */ 1204 if (arc_tune == ARC_TUNE_NONE) 1205 arc_tune = (enum arc_tune_attr) arc_selected_cpu->tune; 1206 1207 if (arc_size_opt_level == 3) 1208 optimize_size = 1; 1209 1210 /* Compact casesi is not a valid option for ARCv2 family. */ 1211 if (TARGET_V2) 1212 { 1213 if (TARGET_COMPACT_CASESI) 1214 { 1215 warning (0, "compact-casesi is not applicable to ARCv2"); 1216 TARGET_COMPACT_CASESI = 0; 1217 } 1218 } 1219 else if (optimize_size == 1 1220 && !global_options_set.x_TARGET_COMPACT_CASESI) 1221 TARGET_COMPACT_CASESI = 1; 1222 1223 if (flag_pic) 1224 target_flags |= MASK_NO_SDATA_SET; 1225 1226 if (flag_no_common == 255) 1227 flag_no_common = !TARGET_NO_SDATA_SET; 1228 1229 /* TARGET_COMPACT_CASESI needs the "q" register class. */ 1230 if (TARGET_MIXED_CODE) 1231 TARGET_Q_CLASS = 1; 1232 if (!TARGET_Q_CLASS) 1233 TARGET_COMPACT_CASESI = 0; 1234 if (TARGET_COMPACT_CASESI) 1235 TARGET_CASE_VECTOR_PC_RELATIVE = 1; 1236 1237 /* Check for small data option */ 1238 if (!global_options_set.x_g_switch_value && !TARGET_NO_SDATA_SET) 1239 g_switch_value = TARGET_LL64 ? 8 : 4; 1240 1241 /* These need to be done at start up. It's convenient to do them here. */ 1242 arc_init (); 1243 } 1244 1245 /* The condition codes of the ARC, and the inverse function. */ 1246 /* For short branches, the "c" / "nc" names are not defined in the ARC 1247 Programmers manual, so we have to use "lo" / "hs"" instead. */ 1248 static const char *arc_condition_codes[] = 1249 { 1250 "al", 0, "eq", "ne", "p", "n", "lo", "hs", "v", "nv", 1251 "gt", "le", "ge", "lt", "hi", "ls", "pnz", 0 1252 }; 1253 1254 enum arc_cc_code_index 1255 { 1256 ARC_CC_AL, ARC_CC_EQ = ARC_CC_AL+2, ARC_CC_NE, ARC_CC_P, ARC_CC_N, 1257 ARC_CC_C, ARC_CC_NC, ARC_CC_V, ARC_CC_NV, 1258 ARC_CC_GT, ARC_CC_LE, ARC_CC_GE, ARC_CC_LT, ARC_CC_HI, ARC_CC_LS, ARC_CC_PNZ, 1259 ARC_CC_LO = ARC_CC_C, ARC_CC_HS = ARC_CC_NC 1260 }; 1261 1262 #define ARC_INVERSE_CONDITION_CODE(X) ((X) ^ 1) 1263 1264 /* Returns the index of the ARC condition code string in 1265 `arc_condition_codes'. COMPARISON should be an rtx like 1266 `(eq (...) (...))'. */ 1267 1268 static int 1269 get_arc_condition_code (rtx comparison) 1270 { 1271 switch (GET_MODE (XEXP (comparison, 0))) 1272 { 1273 case E_CCmode: 1274 case E_SImode: /* For BRcc. */ 1275 switch (GET_CODE (comparison)) 1276 { 1277 case EQ : return ARC_CC_EQ; 1278 case NE : return ARC_CC_NE; 1279 case GT : return ARC_CC_GT; 1280 case LE : return ARC_CC_LE; 1281 case GE : return ARC_CC_GE; 1282 case LT : return ARC_CC_LT; 1283 case GTU : return ARC_CC_HI; 1284 case LEU : return ARC_CC_LS; 1285 case LTU : return ARC_CC_LO; 1286 case GEU : return ARC_CC_HS; 1287 default : gcc_unreachable (); 1288 } 1289 case E_CC_ZNmode: 1290 switch (GET_CODE (comparison)) 1291 { 1292 case EQ : return ARC_CC_EQ; 1293 case NE : return ARC_CC_NE; 1294 case GE: return ARC_CC_P; 1295 case LT: return ARC_CC_N; 1296 case GT : return ARC_CC_PNZ; 1297 default : gcc_unreachable (); 1298 } 1299 case E_CC_Zmode: 1300 switch (GET_CODE (comparison)) 1301 { 1302 case EQ : return ARC_CC_EQ; 1303 case NE : return ARC_CC_NE; 1304 default : gcc_unreachable (); 1305 } 1306 case E_CC_Cmode: 1307 switch (GET_CODE (comparison)) 1308 { 1309 case LTU : return ARC_CC_C; 1310 case GEU : return ARC_CC_NC; 1311 default : gcc_unreachable (); 1312 } 1313 case E_CC_FP_GTmode: 1314 if (TARGET_ARGONAUT_SET && TARGET_SPFP) 1315 switch (GET_CODE (comparison)) 1316 { 1317 case GT : return ARC_CC_N; 1318 case UNLE: return ARC_CC_P; 1319 default : gcc_unreachable (); 1320 } 1321 else 1322 switch (GET_CODE (comparison)) 1323 { 1324 case GT : return ARC_CC_HI; 1325 case UNLE : return ARC_CC_LS; 1326 default : gcc_unreachable (); 1327 } 1328 case E_CC_FP_GEmode: 1329 /* Same for FPX and non-FPX. */ 1330 switch (GET_CODE (comparison)) 1331 { 1332 case GE : return ARC_CC_HS; 1333 case UNLT : return ARC_CC_LO; 1334 default : gcc_unreachable (); 1335 } 1336 case E_CC_FP_UNEQmode: 1337 switch (GET_CODE (comparison)) 1338 { 1339 case UNEQ : return ARC_CC_EQ; 1340 case LTGT : return ARC_CC_NE; 1341 default : gcc_unreachable (); 1342 } 1343 case E_CC_FP_ORDmode: 1344 switch (GET_CODE (comparison)) 1345 { 1346 case UNORDERED : return ARC_CC_C; 1347 case ORDERED : return ARC_CC_NC; 1348 default : gcc_unreachable (); 1349 } 1350 case E_CC_FPXmode: 1351 switch (GET_CODE (comparison)) 1352 { 1353 case EQ : return ARC_CC_EQ; 1354 case NE : return ARC_CC_NE; 1355 case UNORDERED : return ARC_CC_C; 1356 case ORDERED : return ARC_CC_NC; 1357 case LTGT : return ARC_CC_HI; 1358 case UNEQ : return ARC_CC_LS; 1359 default : gcc_unreachable (); 1360 } 1361 case E_CC_FPUmode: 1362 switch (GET_CODE (comparison)) 1363 { 1364 case EQ : return ARC_CC_EQ; 1365 case NE : return ARC_CC_NE; 1366 case GT : return ARC_CC_GT; 1367 case GE : return ARC_CC_GE; 1368 case LT : return ARC_CC_C; 1369 case LE : return ARC_CC_LS; 1370 case UNORDERED : return ARC_CC_V; 1371 case ORDERED : return ARC_CC_NV; 1372 case UNGT : return ARC_CC_HI; 1373 case UNGE : return ARC_CC_HS; 1374 case UNLT : return ARC_CC_LT; 1375 case UNLE : return ARC_CC_LE; 1376 /* UNEQ and LTGT do not have representation. */ 1377 case LTGT : /* Fall through. */ 1378 case UNEQ : /* Fall through. */ 1379 default : gcc_unreachable (); 1380 } 1381 case E_CC_FPU_UNEQmode: 1382 switch (GET_CODE (comparison)) 1383 { 1384 case LTGT : return ARC_CC_NE; 1385 case UNEQ : return ARC_CC_EQ; 1386 default : gcc_unreachable (); 1387 } 1388 default : gcc_unreachable (); 1389 } 1390 /*NOTREACHED*/ 1391 return (42); 1392 } 1393 1394 /* Return true if COMPARISON has a short form that can accomodate OFFSET. */ 1395 1396 bool 1397 arc_short_comparison_p (rtx comparison, int offset) 1398 { 1399 gcc_assert (ARC_CC_NC == ARC_CC_HS); 1400 gcc_assert (ARC_CC_C == ARC_CC_LO); 1401 switch (get_arc_condition_code (comparison)) 1402 { 1403 case ARC_CC_EQ: case ARC_CC_NE: 1404 return offset >= -512 && offset <= 506; 1405 case ARC_CC_GT: case ARC_CC_LE: case ARC_CC_GE: case ARC_CC_LT: 1406 case ARC_CC_HI: case ARC_CC_LS: case ARC_CC_LO: case ARC_CC_HS: 1407 return offset >= -64 && offset <= 58; 1408 default: 1409 return false; 1410 } 1411 } 1412 1413 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE, 1414 return the mode to be used for the comparison. */ 1415 1416 machine_mode 1417 arc_select_cc_mode (enum rtx_code op, rtx x, rtx y) 1418 { 1419 machine_mode mode = GET_MODE (x); 1420 rtx x1; 1421 1422 /* For an operation that sets the condition codes as a side-effect, the 1423 C and V flags is not set as for cmp, so we can only use comparisons where 1424 this doesn't matter. (For LT and GE we can use "mi" and "pl" 1425 instead.) */ 1426 /* ??? We could use "pnz" for greater than zero, however, we could then 1427 get into trouble because the comparison could not be reversed. */ 1428 if (GET_MODE_CLASS (mode) == MODE_INT 1429 && y == const0_rtx 1430 && (op == EQ || op == NE 1431 || ((op == LT || op == GE) && GET_MODE_SIZE (GET_MODE (x)) <= 4))) 1432 return CC_ZNmode; 1433 1434 /* add.f for if (a+b) */ 1435 if (mode == SImode 1436 && GET_CODE (y) == NEG 1437 && (op == EQ || op == NE)) 1438 return CC_ZNmode; 1439 1440 /* Check if this is a test suitable for bxor.f . */ 1441 if (mode == SImode && (op == EQ || op == NE) && CONST_INT_P (y) 1442 && ((INTVAL (y) - 1) & INTVAL (y)) == 0 1443 && INTVAL (y)) 1444 return CC_Zmode; 1445 1446 /* Check if this is a test suitable for add / bmsk.f . */ 1447 if (mode == SImode && (op == EQ || op == NE) && CONST_INT_P (y) 1448 && GET_CODE (x) == AND && CONST_INT_P ((x1 = XEXP (x, 1))) 1449 && ((INTVAL (x1) + 1) & INTVAL (x1)) == 0 1450 && (~INTVAL (x1) | INTVAL (y)) < 0 1451 && (~INTVAL (x1) | INTVAL (y)) > -0x800) 1452 return CC_Zmode; 1453 1454 if (GET_MODE (x) == SImode && (op == LTU || op == GEU) 1455 && GET_CODE (x) == PLUS 1456 && (rtx_equal_p (XEXP (x, 0), y) || rtx_equal_p (XEXP (x, 1), y))) 1457 return CC_Cmode; 1458 1459 if (TARGET_ARGONAUT_SET 1460 && ((mode == SFmode && TARGET_SPFP) || (mode == DFmode && TARGET_DPFP))) 1461 switch (op) 1462 { 1463 case EQ: case NE: case UNEQ: case LTGT: case ORDERED: case UNORDERED: 1464 return CC_FPXmode; 1465 case LT: case UNGE: case GT: case UNLE: 1466 return CC_FP_GTmode; 1467 case LE: case UNGT: case GE: case UNLT: 1468 return CC_FP_GEmode; 1469 default: gcc_unreachable (); 1470 } 1471 else if (TARGET_HARD_FLOAT 1472 && ((mode == SFmode && TARGET_FP_SP_BASE) 1473 || (mode == DFmode && TARGET_FP_DP_BASE))) 1474 switch (op) 1475 { 1476 case EQ: 1477 case NE: 1478 case UNORDERED: 1479 case ORDERED: 1480 case UNLT: 1481 case UNLE: 1482 case UNGT: 1483 case UNGE: 1484 case LT: 1485 case LE: 1486 case GT: 1487 case GE: 1488 return CC_FPUmode; 1489 1490 case LTGT: 1491 case UNEQ: 1492 return CC_FPU_UNEQmode; 1493 1494 default: 1495 gcc_unreachable (); 1496 } 1497 else if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_OPTFPE) 1498 { 1499 switch (op) 1500 { 1501 case EQ: case NE: return CC_Zmode; 1502 case LT: case UNGE: 1503 case GT: case UNLE: return CC_FP_GTmode; 1504 case LE: case UNGT: 1505 case GE: case UNLT: return CC_FP_GEmode; 1506 case UNEQ: case LTGT: return CC_FP_UNEQmode; 1507 case ORDERED: case UNORDERED: return CC_FP_ORDmode; 1508 default: gcc_unreachable (); 1509 } 1510 } 1511 return CCmode; 1512 } 1513 1514 /* Vectors to keep interesting information about registers where it can easily 1515 be got. We use to use the actual mode value as the bit number, but there 1516 is (or may be) more than 32 modes now. Instead we use two tables: one 1517 indexed by hard register number, and one indexed by mode. */ 1518 1519 /* The purpose of arc_mode_class is to shrink the range of modes so that 1520 they all fit (as bit numbers) in a 32-bit word (again). Each real mode is 1521 mapped into one arc_mode_class mode. */ 1522 1523 enum arc_mode_class { 1524 C_MODE, 1525 S_MODE, D_MODE, T_MODE, O_MODE, 1526 SF_MODE, DF_MODE, TF_MODE, OF_MODE, 1527 V_MODE 1528 }; 1529 1530 /* Modes for condition codes. */ 1531 #define C_MODES (1 << (int) C_MODE) 1532 1533 /* Modes for single-word and smaller quantities. */ 1534 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE)) 1535 1536 /* Modes for double-word and smaller quantities. */ 1537 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE)) 1538 1539 /* Mode for 8-byte DF values only. */ 1540 #define DF_MODES (1 << DF_MODE) 1541 1542 /* Modes for quad-word and smaller quantities. */ 1543 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE)) 1544 1545 /* Modes for 128-bit vectors. */ 1546 #define V_MODES (1 << (int) V_MODE) 1547 1548 /* Value is 1 if register/mode pair is acceptable on arc. */ 1549 1550 static unsigned int arc_hard_regno_modes[] = { 1551 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, 1552 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, 1553 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, D_MODES, 1554 D_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, 1555 1556 /* ??? Leave these as S_MODES for now. */ 1557 S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, 1558 DF_MODES, 0, DF_MODES, 0, S_MODES, S_MODES, S_MODES, S_MODES, 1559 S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, 1560 S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, C_MODES, S_MODES, 1561 1562 V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, 1563 V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, 1564 V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, 1565 V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, 1566 1567 V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, 1568 V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, 1569 V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, 1570 V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, V_MODES, 1571 1572 S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, 1573 S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES, S_MODES 1574 }; 1575 1576 static unsigned int arc_mode_class [NUM_MACHINE_MODES]; 1577 1578 enum reg_class arc_regno_reg_class[FIRST_PSEUDO_REGISTER]; 1579 1580 enum reg_class 1581 arc_preferred_reload_class (rtx, enum reg_class cl) 1582 { 1583 if ((cl) == CHEAP_CORE_REGS || (cl) == WRITABLE_CORE_REGS) 1584 return GENERAL_REGS; 1585 return cl; 1586 } 1587 1588 /* Initialize the arc_mode_class array. */ 1589 1590 static void 1591 arc_init_reg_tables (void) 1592 { 1593 int i; 1594 1595 for (i = 0; i < NUM_MACHINE_MODES; i++) 1596 { 1597 machine_mode m = (machine_mode) i; 1598 1599 switch (GET_MODE_CLASS (m)) 1600 { 1601 case MODE_INT: 1602 case MODE_PARTIAL_INT: 1603 case MODE_COMPLEX_INT: 1604 if (GET_MODE_SIZE (m) <= 4) 1605 arc_mode_class[i] = 1 << (int) S_MODE; 1606 else if (GET_MODE_SIZE (m) == 8) 1607 arc_mode_class[i] = 1 << (int) D_MODE; 1608 else if (GET_MODE_SIZE (m) == 16) 1609 arc_mode_class[i] = 1 << (int) T_MODE; 1610 else if (GET_MODE_SIZE (m) == 32) 1611 arc_mode_class[i] = 1 << (int) O_MODE; 1612 else 1613 arc_mode_class[i] = 0; 1614 break; 1615 case MODE_FLOAT: 1616 case MODE_COMPLEX_FLOAT: 1617 if (GET_MODE_SIZE (m) <= 4) 1618 arc_mode_class[i] = 1 << (int) SF_MODE; 1619 else if (GET_MODE_SIZE (m) == 8) 1620 arc_mode_class[i] = 1 << (int) DF_MODE; 1621 else if (GET_MODE_SIZE (m) == 16) 1622 arc_mode_class[i] = 1 << (int) TF_MODE; 1623 else if (GET_MODE_SIZE (m) == 32) 1624 arc_mode_class[i] = 1 << (int) OF_MODE; 1625 else 1626 arc_mode_class[i] = 0; 1627 break; 1628 case MODE_VECTOR_INT: 1629 if (GET_MODE_SIZE (m) == 4) 1630 arc_mode_class[i] = (1 << (int) S_MODE); 1631 else if (GET_MODE_SIZE (m) == 8) 1632 arc_mode_class[i] = (1 << (int) D_MODE); 1633 else 1634 arc_mode_class[i] = (1 << (int) V_MODE); 1635 break; 1636 case MODE_CC: 1637 default: 1638 /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so 1639 we must explicitly check for them here. */ 1640 if (i == (int) CCmode || i == (int) CC_ZNmode || i == (int) CC_Zmode 1641 || i == (int) CC_Cmode 1642 || i == CC_FP_GTmode || i == CC_FP_GEmode || i == CC_FP_ORDmode 1643 || i == CC_FPUmode || i == CC_FPU_UNEQmode) 1644 arc_mode_class[i] = 1 << (int) C_MODE; 1645 else 1646 arc_mode_class[i] = 0; 1647 break; 1648 } 1649 } 1650 } 1651 1652 /* Core registers 56..59 are used for multiply extension options. 1653 The dsp option uses r56 and r57, these are then named acc1 and acc2. 1654 acc1 is the highpart, and acc2 the lowpart, so which register gets which 1655 number depends on endianness. 1656 The mul64 multiplier options use r57 for mlo, r58 for mmid and r59 for mhi. 1657 Because mlo / mhi form a 64 bit value, we use different gcc internal 1658 register numbers to make them form a register pair as the gcc internals 1659 know it. mmid gets number 57, if still available, and mlo / mhi get 1660 number 58 and 59, depending on endianness. We use DBX_REGISTER_NUMBER 1661 to map this back. */ 1662 char rname56[5] = "r56"; 1663 char rname57[5] = "r57"; 1664 char rname58[5] = "r58"; 1665 char rname59[5] = "r59"; 1666 char rname29[7] = "ilink1"; 1667 char rname30[7] = "ilink2"; 1668 1669 static void 1670 arc_conditional_register_usage (void) 1671 { 1672 int regno; 1673 int i; 1674 int fix_start = 60, fix_end = 55; 1675 1676 if (TARGET_V2) 1677 { 1678 /* For ARCv2 the core register set is changed. */ 1679 strcpy (rname29, "ilink"); 1680 strcpy (rname30, "r30"); 1681 1682 if (!TEST_HARD_REG_BIT (overrideregs, 30)) 1683 { 1684 /* No user interference. Set the r30 to be used by the 1685 compiler. */ 1686 call_used_regs[30] = 1; 1687 fixed_regs[30] = 0; 1688 1689 arc_regno_reg_class[30] = WRITABLE_CORE_REGS; 1690 SET_HARD_REG_BIT (reg_class_contents[WRITABLE_CORE_REGS], 30); 1691 SET_HARD_REG_BIT (reg_class_contents[CHEAP_CORE_REGS], 30); 1692 SET_HARD_REG_BIT (reg_class_contents[GENERAL_REGS], 30); 1693 SET_HARD_REG_BIT (reg_class_contents[MPY_WRITABLE_CORE_REGS], 30); 1694 } 1695 } 1696 1697 if (TARGET_MUL64_SET) 1698 { 1699 fix_start = 57; 1700 fix_end = 59; 1701 1702 /* We don't provide a name for mmed. In rtl / assembly resource lists, 1703 you are supposed to refer to it as mlo & mhi, e.g 1704 (zero_extract:SI (reg:DI 58) (const_int 32) (16)) . 1705 In an actual asm instruction, you are of course use mmed. 1706 The point of avoiding having a separate register for mmed is that 1707 this way, we don't have to carry clobbers of that reg around in every 1708 isntruction that modifies mlo and/or mhi. */ 1709 strcpy (rname57, ""); 1710 strcpy (rname58, TARGET_BIG_ENDIAN ? "mhi" : "mlo"); 1711 strcpy (rname59, TARGET_BIG_ENDIAN ? "mlo" : "mhi"); 1712 } 1713 1714 /* The nature of arc_tp_regno is actually something more like a global 1715 register, however globalize_reg requires a declaration. 1716 We use EPILOGUE_USES to compensate so that sets from 1717 __builtin_set_frame_pointer are not deleted. */ 1718 if (arc_tp_regno != -1) 1719 fixed_regs[arc_tp_regno] = call_used_regs[arc_tp_regno] = 1; 1720 1721 if (TARGET_MULMAC_32BY16_SET) 1722 { 1723 fix_start = 56; 1724 fix_end = fix_end > 57 ? fix_end : 57; 1725 strcpy (rname56, TARGET_BIG_ENDIAN ? "acc1" : "acc2"); 1726 strcpy (rname57, TARGET_BIG_ENDIAN ? "acc2" : "acc1"); 1727 } 1728 for (regno = fix_start; regno <= fix_end; regno++) 1729 { 1730 if (!fixed_regs[regno]) 1731 warning (0, "multiply option implies r%d is fixed", regno); 1732 fixed_regs [regno] = call_used_regs[regno] = 1; 1733 } 1734 if (TARGET_Q_CLASS) 1735 { 1736 if (optimize_size) 1737 { 1738 reg_alloc_order[0] = 0; 1739 reg_alloc_order[1] = 1; 1740 reg_alloc_order[2] = 2; 1741 reg_alloc_order[3] = 3; 1742 reg_alloc_order[4] = 12; 1743 reg_alloc_order[5] = 13; 1744 reg_alloc_order[6] = 14; 1745 reg_alloc_order[7] = 15; 1746 reg_alloc_order[8] = 4; 1747 reg_alloc_order[9] = 5; 1748 reg_alloc_order[10] = 6; 1749 reg_alloc_order[11] = 7; 1750 reg_alloc_order[12] = 8; 1751 reg_alloc_order[13] = 9; 1752 reg_alloc_order[14] = 10; 1753 reg_alloc_order[15] = 11; 1754 } 1755 else 1756 { 1757 reg_alloc_order[2] = 12; 1758 reg_alloc_order[3] = 13; 1759 reg_alloc_order[4] = 14; 1760 reg_alloc_order[5] = 15; 1761 reg_alloc_order[6] = 1; 1762 reg_alloc_order[7] = 0; 1763 reg_alloc_order[8] = 4; 1764 reg_alloc_order[9] = 5; 1765 reg_alloc_order[10] = 6; 1766 reg_alloc_order[11] = 7; 1767 reg_alloc_order[12] = 8; 1768 reg_alloc_order[13] = 9; 1769 reg_alloc_order[14] = 10; 1770 reg_alloc_order[15] = 11; 1771 } 1772 } 1773 if (TARGET_SIMD_SET) 1774 { 1775 int i; 1776 for (i = ARC_FIRST_SIMD_VR_REG; i <= ARC_LAST_SIMD_VR_REG; i++) 1777 reg_alloc_order [i] = i; 1778 for (i = ARC_FIRST_SIMD_DMA_CONFIG_REG; 1779 i <= ARC_LAST_SIMD_DMA_CONFIG_REG; i++) 1780 reg_alloc_order [i] = i; 1781 } 1782 1783 /* Reduced configuration: don't use r4-r9, r16-r25. */ 1784 if (TARGET_RF16) 1785 { 1786 for (i = 4; i <= 9; i++) 1787 { 1788 fixed_regs[i] = call_used_regs[i] = 1; 1789 } 1790 for (i = 16; i <= 25; i++) 1791 { 1792 fixed_regs[i] = call_used_regs[i] = 1; 1793 } 1794 } 1795 1796 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) 1797 if (!call_used_regs[regno]) 1798 CLEAR_HARD_REG_BIT (reg_class_contents[SIBCALL_REGS], regno); 1799 for (regno = 32; regno < 60; regno++) 1800 if (!fixed_regs[regno]) 1801 SET_HARD_REG_BIT (reg_class_contents[WRITABLE_CORE_REGS], regno); 1802 if (!TARGET_ARC600_FAMILY) 1803 { 1804 for (regno = 32; regno <= 60; regno++) 1805 CLEAR_HARD_REG_BIT (reg_class_contents[CHEAP_CORE_REGS], regno); 1806 1807 /* If they have used -ffixed-lp_count, make sure it takes 1808 effect. */ 1809 if (fixed_regs[LP_COUNT]) 1810 { 1811 CLEAR_HARD_REG_BIT (reg_class_contents[LPCOUNT_REG], LP_COUNT); 1812 CLEAR_HARD_REG_BIT (reg_class_contents[SIBCALL_REGS], LP_COUNT); 1813 CLEAR_HARD_REG_BIT (reg_class_contents[WRITABLE_CORE_REGS], LP_COUNT); 1814 1815 /* Instead of taking out SF_MODE like below, forbid it outright. */ 1816 arc_hard_regno_modes[60] = 0; 1817 } 1818 else 1819 arc_hard_regno_modes[60] = 1 << (int) S_MODE; 1820 } 1821 1822 /* ARCHS has 64-bit data-path which makes use of the even-odd paired 1823 registers. */ 1824 if (TARGET_HS) 1825 { 1826 for (regno = 1; regno < 32; regno +=2) 1827 { 1828 arc_hard_regno_modes[regno] = S_MODES; 1829 } 1830 } 1831 1832 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) 1833 { 1834 if (i < 29) 1835 { 1836 if ((TARGET_Q_CLASS || TARGET_RRQ_CLASS) 1837 && ((i <= 3) || ((i >= 12) && (i <= 15)))) 1838 arc_regno_reg_class[i] = ARCOMPACT16_REGS; 1839 else 1840 arc_regno_reg_class[i] = GENERAL_REGS; 1841 } 1842 else if (i < 60) 1843 arc_regno_reg_class[i] 1844 = (fixed_regs[i] 1845 ? (TEST_HARD_REG_BIT (reg_class_contents[CHEAP_CORE_REGS], i) 1846 ? CHEAP_CORE_REGS : ALL_CORE_REGS) 1847 : (((!TARGET_ARC600_FAMILY) 1848 && TEST_HARD_REG_BIT (reg_class_contents[CHEAP_CORE_REGS], i)) 1849 ? CHEAP_CORE_REGS : WRITABLE_CORE_REGS)); 1850 else 1851 arc_regno_reg_class[i] = NO_REGS; 1852 } 1853 1854 /* ARCOMPACT16_REGS is empty, if TARGET_Q_CLASS / TARGET_RRQ_CLASS 1855 has not been activated. */ 1856 if (!TARGET_Q_CLASS && !TARGET_RRQ_CLASS) 1857 CLEAR_HARD_REG_SET(reg_class_contents [ARCOMPACT16_REGS]); 1858 if (!TARGET_Q_CLASS) 1859 CLEAR_HARD_REG_SET(reg_class_contents [AC16_BASE_REGS]); 1860 1861 gcc_assert (FIRST_PSEUDO_REGISTER >= 144); 1862 1863 /* Handle Special Registers. */ 1864 arc_regno_reg_class[29] = LINK_REGS; /* ilink1 register. */ 1865 if (!TARGET_V2) 1866 arc_regno_reg_class[30] = LINK_REGS; /* ilink2 register. */ 1867 arc_regno_reg_class[31] = LINK_REGS; /* blink register. */ 1868 arc_regno_reg_class[60] = LPCOUNT_REG; 1869 arc_regno_reg_class[61] = NO_REGS; /* CC_REG: must be NO_REGS. */ 1870 arc_regno_reg_class[62] = GENERAL_REGS; 1871 1872 if (TARGET_DPFP) 1873 { 1874 for (i = 40; i < 44; ++i) 1875 { 1876 arc_regno_reg_class[i] = DOUBLE_REGS; 1877 1878 /* Unless they want us to do 'mov d1, 0x00000000' make sure 1879 no attempt is made to use such a register as a destination 1880 operand in *movdf_insn. */ 1881 if (!TARGET_ARGONAUT_SET) 1882 { 1883 /* Make sure no 'c', 'w', 'W', or 'Rac' constraint is 1884 interpreted to mean they can use D1 or D2 in their insn. */ 1885 CLEAR_HARD_REG_BIT(reg_class_contents[CHEAP_CORE_REGS ], i); 1886 CLEAR_HARD_REG_BIT(reg_class_contents[ALL_CORE_REGS ], i); 1887 CLEAR_HARD_REG_BIT(reg_class_contents[WRITABLE_CORE_REGS ], i); 1888 CLEAR_HARD_REG_BIT(reg_class_contents[MPY_WRITABLE_CORE_REGS], i); 1889 } 1890 } 1891 } 1892 else 1893 { 1894 /* Disable all DOUBLE_REGISTER settings, 1895 if not generating DPFP code. */ 1896 arc_regno_reg_class[40] = ALL_REGS; 1897 arc_regno_reg_class[41] = ALL_REGS; 1898 arc_regno_reg_class[42] = ALL_REGS; 1899 arc_regno_reg_class[43] = ALL_REGS; 1900 1901 fixed_regs[40] = 1; 1902 fixed_regs[41] = 1; 1903 fixed_regs[42] = 1; 1904 fixed_regs[43] = 1; 1905 1906 arc_hard_regno_modes[40] = 0; 1907 arc_hard_regno_modes[42] = 0; 1908 1909 CLEAR_HARD_REG_SET(reg_class_contents [DOUBLE_REGS]); 1910 } 1911 1912 if (TARGET_SIMD_SET) 1913 { 1914 gcc_assert (ARC_FIRST_SIMD_VR_REG == 64); 1915 gcc_assert (ARC_LAST_SIMD_VR_REG == 127); 1916 1917 for (i = ARC_FIRST_SIMD_VR_REG; i <= ARC_LAST_SIMD_VR_REG; i++) 1918 arc_regno_reg_class [i] = SIMD_VR_REGS; 1919 1920 gcc_assert (ARC_FIRST_SIMD_DMA_CONFIG_REG == 128); 1921 gcc_assert (ARC_FIRST_SIMD_DMA_CONFIG_IN_REG == 128); 1922 gcc_assert (ARC_FIRST_SIMD_DMA_CONFIG_OUT_REG == 136); 1923 gcc_assert (ARC_LAST_SIMD_DMA_CONFIG_REG == 143); 1924 1925 for (i = ARC_FIRST_SIMD_DMA_CONFIG_REG; 1926 i <= ARC_LAST_SIMD_DMA_CONFIG_REG; i++) 1927 arc_regno_reg_class [i] = SIMD_DMA_CONFIG_REGS; 1928 } 1929 1930 /* pc : r63 */ 1931 arc_regno_reg_class[PROGRAM_COUNTER_REGNO] = GENERAL_REGS; 1932 1933 /*ARCV2 Accumulator. */ 1934 if ((TARGET_V2 1935 && (TARGET_FP_DP_FUSED || TARGET_FP_SP_FUSED)) 1936 || TARGET_PLUS_DMPY) 1937 { 1938 arc_regno_reg_class[ACCL_REGNO] = WRITABLE_CORE_REGS; 1939 arc_regno_reg_class[ACCH_REGNO] = WRITABLE_CORE_REGS; 1940 SET_HARD_REG_BIT (reg_class_contents[WRITABLE_CORE_REGS], ACCL_REGNO); 1941 SET_HARD_REG_BIT (reg_class_contents[WRITABLE_CORE_REGS], ACCH_REGNO); 1942 SET_HARD_REG_BIT (reg_class_contents[CHEAP_CORE_REGS], ACCL_REGNO); 1943 SET_HARD_REG_BIT (reg_class_contents[CHEAP_CORE_REGS], ACCH_REGNO); 1944 SET_HARD_REG_BIT (reg_class_contents[GENERAL_REGS], ACCL_REGNO); 1945 SET_HARD_REG_BIT (reg_class_contents[GENERAL_REGS], ACCH_REGNO); 1946 SET_HARD_REG_BIT (reg_class_contents[MPY_WRITABLE_CORE_REGS], ACCL_REGNO); 1947 SET_HARD_REG_BIT (reg_class_contents[MPY_WRITABLE_CORE_REGS], ACCH_REGNO); 1948 1949 /* Allow the compiler to freely use them. */ 1950 if (!TEST_HARD_REG_BIT (overrideregs, ACCL_REGNO)) 1951 fixed_regs[ACCL_REGNO] = 0; 1952 if (!TEST_HARD_REG_BIT (overrideregs, ACCH_REGNO)) 1953 fixed_regs[ACCH_REGNO] = 0; 1954 1955 if (!fixed_regs[ACCH_REGNO] && !fixed_regs[ACCL_REGNO]) 1956 arc_hard_regno_modes[ACC_REG_FIRST] = D_MODES; 1957 } 1958 } 1959 1960 /* Implement TARGET_HARD_REGNO_NREGS. */ 1961 1962 static unsigned int 1963 arc_hard_regno_nregs (unsigned int regno, machine_mode mode) 1964 { 1965 if (GET_MODE_SIZE (mode) == 16 1966 && regno >= ARC_FIRST_SIMD_VR_REG 1967 && regno <= ARC_LAST_SIMD_VR_REG) 1968 return 1; 1969 1970 return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD); 1971 } 1972 1973 /* Implement TARGET_HARD_REGNO_MODE_OK. */ 1974 1975 static bool 1976 arc_hard_regno_mode_ok (unsigned int regno, machine_mode mode) 1977 { 1978 return (arc_hard_regno_modes[regno] & arc_mode_class[mode]) != 0; 1979 } 1980 1981 /* Implement TARGET_MODES_TIEABLE_P. Tie QI/HI/SI modes together. */ 1982 1983 static bool 1984 arc_modes_tieable_p (machine_mode mode1, machine_mode mode2) 1985 { 1986 return (GET_MODE_CLASS (mode1) == MODE_INT 1987 && GET_MODE_CLASS (mode2) == MODE_INT 1988 && GET_MODE_SIZE (mode1) <= UNITS_PER_WORD 1989 && GET_MODE_SIZE (mode2) <= UNITS_PER_WORD); 1990 } 1991 1992 /* Handle an "interrupt" attribute; arguments as in 1993 struct attribute_spec.handler. */ 1994 1995 static tree 1996 arc_handle_interrupt_attribute (tree *, tree name, tree args, int, 1997 bool *no_add_attrs) 1998 { 1999 gcc_assert (args); 2000 2001 tree value = TREE_VALUE (args); 2002 2003 if (TREE_CODE (value) != STRING_CST) 2004 { 2005 warning (OPT_Wattributes, 2006 "argument of %qE attribute is not a string constant", 2007 name); 2008 *no_add_attrs = true; 2009 } 2010 else if (!TARGET_V2 2011 && strcmp (TREE_STRING_POINTER (value), "ilink1") 2012 && strcmp (TREE_STRING_POINTER (value), "ilink2")) 2013 { 2014 warning (OPT_Wattributes, 2015 "argument of %qE attribute is not \"ilink1\" or \"ilink2\"", 2016 name); 2017 *no_add_attrs = true; 2018 } 2019 else if (TARGET_V2 2020 && strcmp (TREE_STRING_POINTER (value), "ilink") 2021 && strcmp (TREE_STRING_POINTER (value), "firq")) 2022 { 2023 warning (OPT_Wattributes, 2024 "argument of %qE attribute is not \"ilink\" or \"firq\"", 2025 name); 2026 *no_add_attrs = true; 2027 } 2028 2029 return NULL_TREE; 2030 } 2031 2032 static tree 2033 arc_handle_fndecl_attribute (tree *node, tree name, tree args ATTRIBUTE_UNUSED, 2034 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs) 2035 { 2036 if (TREE_CODE (*node) != FUNCTION_DECL) 2037 { 2038 warning (OPT_Wattributes, "%qE attribute only applies to functions", 2039 name); 2040 *no_add_attrs = true; 2041 } 2042 2043 return NULL_TREE; 2044 } 2045 2046 /* Implement `TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS' */ 2047 2048 static bool 2049 arc_allocate_stack_slots_for_args (void) 2050 { 2051 /* Naked functions should not allocate stack slots for arguments. */ 2052 unsigned int fn_type = arc_compute_function_type (cfun); 2053 2054 return !ARC_NAKED_P(fn_type); 2055 } 2056 2057 /* Implement `TARGET_WARN_FUNC_RETURN'. */ 2058 2059 static bool 2060 arc_warn_func_return (tree decl) 2061 { 2062 struct function *func = DECL_STRUCT_FUNCTION (decl); 2063 unsigned int fn_type = arc_compute_function_type (func); 2064 2065 return !ARC_NAKED_P (fn_type); 2066 } 2067 2068 /* Return zero if TYPE1 and TYPE are incompatible, one if they are compatible, 2069 and two if they are nearly compatible (which causes a warning to be 2070 generated). */ 2071 2072 static int 2073 arc_comp_type_attributes (const_tree type1, 2074 const_tree type2) 2075 { 2076 int l1, l2, m1, m2, s1, s2; 2077 2078 /* Check for mismatch of non-default calling convention. */ 2079 if (TREE_CODE (type1) != FUNCTION_TYPE) 2080 return 1; 2081 2082 /* Check for mismatched call attributes. */ 2083 l1 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type1)) != NULL; 2084 l2 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type2)) != NULL; 2085 m1 = lookup_attribute ("medium_call", TYPE_ATTRIBUTES (type1)) != NULL; 2086 m2 = lookup_attribute ("medium_call", TYPE_ATTRIBUTES (type2)) != NULL; 2087 s1 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type1)) != NULL; 2088 s2 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type2)) != NULL; 2089 2090 /* Only bother to check if an attribute is defined. */ 2091 if (l1 | l2 | m1 | m2 | s1 | s2) 2092 { 2093 /* If one type has an attribute, the other must have the same attribute. */ 2094 if ((l1 != l2) || (m1 != m2) || (s1 != s2)) 2095 return 0; 2096 2097 /* Disallow mixed attributes. */ 2098 if (l1 + m1 + s1 > 1) 2099 return 0; 2100 } 2101 2102 2103 return 1; 2104 } 2105 2106 /* Misc. utilities. */ 2107 2108 /* X and Y are two things to compare using CODE. Emit the compare insn and 2109 return the rtx for the cc reg in the proper mode. */ 2110 2111 rtx 2112 gen_compare_reg (rtx comparison, machine_mode omode) 2113 { 2114 enum rtx_code code = GET_CODE (comparison); 2115 rtx x = XEXP (comparison, 0); 2116 rtx y = XEXP (comparison, 1); 2117 rtx tmp, cc_reg; 2118 machine_mode mode, cmode; 2119 2120 2121 cmode = GET_MODE (x); 2122 if (cmode == VOIDmode) 2123 cmode = GET_MODE (y); 2124 gcc_assert (cmode == SImode || cmode == SFmode || cmode == DFmode); 2125 if (cmode == SImode) 2126 { 2127 if (!register_operand (x, SImode)) 2128 { 2129 if (register_operand (y, SImode)) 2130 { 2131 tmp = x; 2132 x = y; 2133 y = tmp; 2134 code = swap_condition (code); 2135 } 2136 else 2137 x = copy_to_mode_reg (SImode, x); 2138 } 2139 if (GET_CODE (y) == SYMBOL_REF && flag_pic) 2140 y = copy_to_mode_reg (SImode, y); 2141 } 2142 else 2143 { 2144 x = force_reg (cmode, x); 2145 y = force_reg (cmode, y); 2146 } 2147 mode = SELECT_CC_MODE (code, x, y); 2148 2149 cc_reg = gen_rtx_REG (mode, CC_REG); 2150 2151 /* ??? FIXME (x-y)==0, as done by both cmpsfpx_raw and 2152 cmpdfpx_raw, is not a correct comparison for floats: 2153 http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm 2154 */ 2155 if (TARGET_ARGONAUT_SET 2156 && ((cmode == SFmode && TARGET_SPFP) || (cmode == DFmode && TARGET_DPFP))) 2157 { 2158 switch (code) 2159 { 2160 case NE: case EQ: case LT: case UNGE: case LE: case UNGT: 2161 case UNEQ: case LTGT: case ORDERED: case UNORDERED: 2162 break; 2163 case GT: case UNLE: case GE: case UNLT: 2164 code = swap_condition (code); 2165 tmp = x; 2166 x = y; 2167 y = tmp; 2168 break; 2169 default: 2170 gcc_unreachable (); 2171 } 2172 if (cmode == SFmode) 2173 { 2174 emit_insn (gen_cmpsfpx_raw (x, y)); 2175 } 2176 else /* DFmode */ 2177 { 2178 /* Accepts Dx regs directly by insns. */ 2179 emit_insn (gen_cmpdfpx_raw (x, y)); 2180 } 2181 2182 if (mode != CC_FPXmode) 2183 emit_insn (gen_rtx_SET (cc_reg, 2184 gen_rtx_COMPARE (mode, 2185 gen_rtx_REG (CC_FPXmode, 61), 2186 const0_rtx))); 2187 } 2188 else if (TARGET_FPX_QUARK && (cmode == SFmode)) 2189 { 2190 switch (code) 2191 { 2192 case NE: case EQ: case GT: case UNLE: case GE: case UNLT: 2193 case UNEQ: case LTGT: case ORDERED: case UNORDERED: 2194 break; 2195 case LT: case UNGE: case LE: case UNGT: 2196 code = swap_condition (code); 2197 tmp = x; 2198 x = y; 2199 y = tmp; 2200 break; 2201 default: 2202 gcc_unreachable (); 2203 } 2204 2205 emit_insn (gen_cmp_quark (cc_reg, 2206 gen_rtx_COMPARE (mode, x, y))); 2207 } 2208 else if (TARGET_HARD_FLOAT 2209 && ((cmode == SFmode && TARGET_FP_SP_BASE) 2210 || (cmode == DFmode && TARGET_FP_DP_BASE))) 2211 emit_insn (gen_rtx_SET (cc_reg, gen_rtx_COMPARE (mode, x, y))); 2212 else if (GET_MODE_CLASS (cmode) == MODE_FLOAT && TARGET_OPTFPE) 2213 { 2214 rtx op0 = gen_rtx_REG (cmode, 0); 2215 rtx op1 = gen_rtx_REG (cmode, GET_MODE_SIZE (cmode) / UNITS_PER_WORD); 2216 bool swap = false; 2217 2218 switch (code) 2219 { 2220 case NE: case EQ: case GT: case UNLE: case GE: case UNLT: 2221 case UNEQ: case LTGT: case ORDERED: case UNORDERED: 2222 break; 2223 case LT: case UNGE: case LE: case UNGT: 2224 code = swap_condition (code); 2225 swap = true; 2226 break; 2227 default: 2228 gcc_unreachable (); 2229 } 2230 if (currently_expanding_to_rtl) 2231 { 2232 if (swap) 2233 { 2234 tmp = x; 2235 x = y; 2236 y = tmp; 2237 } 2238 emit_move_insn (op0, x); 2239 emit_move_insn (op1, y); 2240 } 2241 else 2242 { 2243 gcc_assert (rtx_equal_p (op0, x)); 2244 gcc_assert (rtx_equal_p (op1, y)); 2245 if (swap) 2246 { 2247 op0 = y; 2248 op1 = x; 2249 } 2250 } 2251 emit_insn (gen_cmp_float (cc_reg, gen_rtx_COMPARE (mode, op0, op1))); 2252 } 2253 else 2254 emit_insn (gen_rtx_SET (cc_reg, gen_rtx_COMPARE (mode, x, y))); 2255 return gen_rtx_fmt_ee (code, omode, cc_reg, const0_rtx); 2256 } 2257 2258 /* Return true if VALUE, a const_double, will fit in a limm (4 byte number). 2259 We assume the value can be either signed or unsigned. */ 2260 2261 bool 2262 arc_double_limm_p (rtx value) 2263 { 2264 HOST_WIDE_INT low, high; 2265 2266 gcc_assert (GET_CODE (value) == CONST_DOUBLE); 2267 2268 if (TARGET_DPFP) 2269 return true; 2270 2271 low = CONST_DOUBLE_LOW (value); 2272 high = CONST_DOUBLE_HIGH (value); 2273 2274 if (low & 0x80000000) 2275 { 2276 return (((unsigned HOST_WIDE_INT) low <= 0xffffffff && high == 0) 2277 || (((low & - (unsigned HOST_WIDE_INT) 0x80000000) 2278 == - (unsigned HOST_WIDE_INT) 0x80000000) 2279 && high == -1)); 2280 } 2281 else 2282 { 2283 return (unsigned HOST_WIDE_INT) low <= 0x7fffffff && high == 0; 2284 } 2285 } 2286 2287 /* Do any needed setup for a variadic function. For the ARC, we must 2288 create a register parameter block, and then copy any anonymous arguments 2289 in registers to memory. 2290 2291 CUM has not been updated for the last named argument which has type TYPE 2292 and mode MODE, and we rely on this fact. */ 2293 2294 static void 2295 arc_setup_incoming_varargs (cumulative_args_t args_so_far, 2296 machine_mode mode, tree type, 2297 int *pretend_size, int no_rtl) 2298 { 2299 int first_anon_arg; 2300 CUMULATIVE_ARGS next_cum; 2301 2302 /* We must treat `__builtin_va_alist' as an anonymous arg. */ 2303 2304 next_cum = *get_cumulative_args (args_so_far); 2305 arc_function_arg_advance (pack_cumulative_args (&next_cum), 2306 mode, type, true); 2307 first_anon_arg = next_cum; 2308 2309 if (FUNCTION_ARG_REGNO_P (first_anon_arg)) 2310 { 2311 /* First anonymous (unnamed) argument is in a reg. */ 2312 2313 /* Note that first_reg_offset < MAX_ARC_PARM_REGS. */ 2314 int first_reg_offset = first_anon_arg; 2315 2316 if (!no_rtl) 2317 { 2318 rtx regblock 2319 = gen_rtx_MEM (BLKmode, plus_constant (Pmode, arg_pointer_rtx, 2320 FIRST_PARM_OFFSET (0))); 2321 move_block_from_reg (first_reg_offset, regblock, 2322 MAX_ARC_PARM_REGS - first_reg_offset); 2323 } 2324 2325 *pretend_size 2326 = ((MAX_ARC_PARM_REGS - first_reg_offset ) * UNITS_PER_WORD); 2327 } 2328 } 2329 2330 /* Cost functions. */ 2331 2332 /* Provide the costs of an addressing mode that contains ADDR. 2333 If ADDR is not a valid address, its cost is irrelevant. */ 2334 2335 static int 2336 arc_address_cost (rtx addr, machine_mode, addr_space_t, bool speed) 2337 { 2338 switch (GET_CODE (addr)) 2339 { 2340 case REG : 2341 return speed || satisfies_constraint_Rcq (addr) ? 0 : 1; 2342 case PRE_INC: case PRE_DEC: case POST_INC: case POST_DEC: 2343 case PRE_MODIFY: case POST_MODIFY: 2344 return !speed; 2345 2346 case LABEL_REF : 2347 case SYMBOL_REF : 2348 case CONST : 2349 if (TARGET_NPS_CMEM && cmem_address (addr, SImode)) 2350 return 0; 2351 /* Most likely needs a LIMM. */ 2352 return COSTS_N_INSNS (1); 2353 2354 case PLUS : 2355 { 2356 register rtx plus0 = XEXP (addr, 0); 2357 register rtx plus1 = XEXP (addr, 1); 2358 2359 if (GET_CODE (plus0) != REG 2360 && (GET_CODE (plus0) != MULT 2361 || !CONST_INT_P (XEXP (plus0, 1)) 2362 || (INTVAL (XEXP (plus0, 1)) != 2 2363 && INTVAL (XEXP (plus0, 1)) != 4))) 2364 break; 2365 2366 switch (GET_CODE (plus1)) 2367 { 2368 case CONST_INT : 2369 return (!RTX_OK_FOR_OFFSET_P (SImode, plus1) 2370 ? COSTS_N_INSNS (1) 2371 : speed 2372 ? 0 2373 : (satisfies_constraint_Rcq (plus0) 2374 && satisfies_constraint_O (plus1)) 2375 ? 0 2376 : 1); 2377 case REG: 2378 return (speed < 1 ? 0 2379 : (satisfies_constraint_Rcq (plus0) 2380 && satisfies_constraint_Rcq (plus1)) 2381 ? 0 : 1); 2382 case CONST : 2383 case SYMBOL_REF : 2384 case LABEL_REF : 2385 return COSTS_N_INSNS (1); 2386 default: 2387 break; 2388 } 2389 break; 2390 } 2391 default: 2392 break; 2393 } 2394 2395 return 4; 2396 } 2397 2398 /* Emit instruction X with the frame related bit set. */ 2399 2400 static rtx 2401 frame_insn (rtx x) 2402 { 2403 x = emit_insn (x); 2404 RTX_FRAME_RELATED_P (x) = 1; 2405 return x; 2406 } 2407 2408 /* Emit a frame insn to move SRC to DST. */ 2409 2410 static rtx 2411 frame_move (rtx dst, rtx src) 2412 { 2413 rtx tmp = gen_rtx_SET (dst, src); 2414 RTX_FRAME_RELATED_P (tmp) = 1; 2415 return frame_insn (tmp); 2416 } 2417 2418 /* Like frame_move, but add a REG_INC note for REG if ADDR contains an 2419 auto increment address, or is zero. */ 2420 2421 static rtx 2422 frame_move_inc (rtx dst, rtx src, rtx reg, rtx addr) 2423 { 2424 rtx insn = frame_move (dst, src); 2425 2426 if (!addr 2427 || GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == POST_INC 2428 || GET_CODE (addr) == PRE_MODIFY || GET_CODE (addr) == POST_MODIFY) 2429 add_reg_note (insn, REG_INC, reg); 2430 return insn; 2431 } 2432 2433 /* Emit a frame insn which adjusts a frame address register REG by OFFSET. */ 2434 2435 static rtx 2436 frame_add (rtx reg, HOST_WIDE_INT offset) 2437 { 2438 gcc_assert ((offset & 0x3) == 0); 2439 if (!offset) 2440 return NULL_RTX; 2441 return frame_move (reg, plus_constant (Pmode, reg, offset)); 2442 } 2443 2444 /* Emit a frame insn which adjusts stack pointer by OFFSET. */ 2445 2446 static rtx 2447 frame_stack_add (HOST_WIDE_INT offset) 2448 { 2449 return frame_add (stack_pointer_rtx, offset); 2450 } 2451 2452 /* Traditionally, we push saved registers first in the prologue, 2453 then we allocate the rest of the frame - and reverse in the epilogue. 2454 This has still its merits for ease of debugging, or saving code size 2455 or even execution time if the stack frame is so large that some accesses 2456 can't be encoded anymore with offsets in the instruction code when using 2457 a different scheme. 2458 Also, it would be a good starting point if we got instructions to help 2459 with register save/restore. 2460 2461 However, often stack frames are small, and the pushing / popping has 2462 some costs: 2463 - the stack modification prevents a lot of scheduling. 2464 - frame allocation / deallocation needs extra instructions. 2465 - unless we know that we compile ARC700 user code, we need to put 2466 a memory barrier after frame allocation / before deallocation to 2467 prevent interrupts clobbering our data in the frame. 2468 In particular, we don't have any such guarantees for library functions, 2469 which tend to, on the other hand, to have small frames. 2470 2471 Thus, for small frames, we'd like to use a different scheme: 2472 - The frame is allocated in full with the first prologue instruction, 2473 and deallocated in full with the last epilogue instruction. 2474 Thus, the instructions in-betwen can be freely scheduled. 2475 - If the function has no outgoing arguments on the stack, we can allocate 2476 one register save slot at the top of the stack. This register can then 2477 be saved simultanously with frame allocation, and restored with 2478 frame deallocation. 2479 This register can be picked depending on scheduling considerations, 2480 although same though should go into having some set of registers 2481 to be potentially lingering after a call, and others to be available 2482 immediately - i.e. in the absence of interprocedual optimization, we 2483 can use an ABI-like convention for register allocation to reduce 2484 stalls after function return. */ 2485 /* Function prologue/epilogue handlers. */ 2486 2487 /* ARCompact stack frames look like: 2488 2489 Before call After call 2490 high +-----------------------+ +-----------------------+ 2491 mem | reg parm save area | | reg parm save area | 2492 | only created for | | only created for | 2493 | variable arg fns | | variable arg fns | 2494 AP +-----------------------+ +-----------------------+ 2495 | return addr register | | return addr register | 2496 | (if required) | | (if required) | 2497 +-----------------------+ +-----------------------+ 2498 | | | | 2499 | reg save area | | reg save area | 2500 | | | | 2501 +-----------------------+ +-----------------------+ 2502 | frame pointer | | frame pointer | 2503 | (if required) | | (if required) | 2504 FP +-----------------------+ +-----------------------+ 2505 | | | | 2506 | local/temp variables | | local/temp variables | 2507 | | | | 2508 +-----------------------+ +-----------------------+ 2509 | | | | 2510 | arguments on stack | | arguments on stack | 2511 | | | | 2512 SP +-----------------------+ +-----------------------+ 2513 | reg parm save area | 2514 | only created for | 2515 | variable arg fns | 2516 AP +-----------------------+ 2517 | return addr register | 2518 | (if required) | 2519 +-----------------------+ 2520 | | 2521 | reg save area | 2522 | | 2523 +-----------------------+ 2524 | frame pointer | 2525 | (if required) | 2526 FP +-----------------------+ 2527 | | 2528 | local/temp variables | 2529 | | 2530 +-----------------------+ 2531 | | 2532 | arguments on stack | 2533 low | | 2534 mem SP +-----------------------+ 2535 2536 Notes: 2537 1) The "reg parm save area" does not exist for non variable argument fns. 2538 The "reg parm save area" can be eliminated completely if we created our 2539 own va-arc.h, but that has tradeoffs as well (so it's not done). */ 2540 2541 /* Structure to be filled in by arc_compute_frame_size with register 2542 save masks, and offsets for the current function. */ 2543 struct GTY (()) arc_frame_info 2544 { 2545 unsigned int total_size; /* # bytes that the entire frame takes up. */ 2546 unsigned int extra_size; /* # bytes of extra stuff. */ 2547 unsigned int pretend_size; /* # bytes we push and pretend caller did. */ 2548 unsigned int args_size; /* # bytes that outgoing arguments take up. */ 2549 unsigned int reg_size; /* # bytes needed to store regs. */ 2550 unsigned int var_size; /* # bytes that variables take up. */ 2551 unsigned int reg_offset; /* Offset from new sp to store regs. */ 2552 unsigned int gmask; /* Mask of saved gp registers. */ 2553 int initialized; /* Nonzero if frame size already calculated. */ 2554 short millicode_start_reg; 2555 short millicode_end_reg; 2556 bool save_return_addr; 2557 }; 2558 2559 /* Defining data structures for per-function information. */ 2560 2561 typedef struct GTY (()) machine_function 2562 { 2563 unsigned int fn_type; 2564 struct arc_frame_info frame_info; 2565 /* To keep track of unalignment caused by short insns. */ 2566 int unalign; 2567 struct arc_ccfsm ccfsm_current; 2568 /* Map from uid to ccfsm state during branch shortening. */ 2569 rtx ccfsm_current_insn; 2570 char arc_reorg_started; 2571 char prescan_initialized; 2572 } machine_function; 2573 2574 /* Type of function DECL. 2575 2576 The result is cached. To reset the cache at the end of a function, 2577 call with DECL = NULL_TREE. */ 2578 2579 unsigned int 2580 arc_compute_function_type (struct function *fun) 2581 { 2582 tree attr, decl = fun->decl; 2583 unsigned int fn_type = fun->machine->fn_type; 2584 2585 if (fn_type != ARC_FUNCTION_UNKNOWN) 2586 return fn_type; 2587 2588 /* Check if it is a naked function. */ 2589 if (lookup_attribute ("naked", DECL_ATTRIBUTES (decl)) != NULL_TREE) 2590 fn_type |= ARC_FUNCTION_NAKED; 2591 else 2592 fn_type |= ARC_FUNCTION_NORMAL; 2593 2594 /* Now see if this is an interrupt handler. */ 2595 attr = lookup_attribute ("interrupt", DECL_ATTRIBUTES (decl)); 2596 if (attr != NULL_TREE) 2597 { 2598 tree value, args = TREE_VALUE (attr); 2599 2600 gcc_assert (list_length (args) == 1); 2601 value = TREE_VALUE (args); 2602 gcc_assert (TREE_CODE (value) == STRING_CST); 2603 2604 if (!strcmp (TREE_STRING_POINTER (value), "ilink1") 2605 || !strcmp (TREE_STRING_POINTER (value), "ilink")) 2606 fn_type |= ARC_FUNCTION_ILINK1; 2607 else if (!strcmp (TREE_STRING_POINTER (value), "ilink2")) 2608 fn_type |= ARC_FUNCTION_ILINK2; 2609 else if (!strcmp (TREE_STRING_POINTER (value), "firq")) 2610 fn_type |= ARC_FUNCTION_FIRQ; 2611 else 2612 gcc_unreachable (); 2613 } 2614 2615 return fun->machine->fn_type = fn_type; 2616 } 2617 2618 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM)) 2619 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM)) 2620 2621 /* Tell prologue and epilogue if register REGNO should be saved / restored. 2622 The return address and frame pointer are treated separately. 2623 Don't consider them here. 2624 Addition for pic: The gp register needs to be saved if the current 2625 function changes it to access gotoff variables. 2626 FIXME: This will not be needed if we used some arbitrary register 2627 instead of r26. */ 2628 2629 static bool 2630 arc_must_save_register (int regno, struct function *func) 2631 { 2632 unsigned int fn_type = arc_compute_function_type (func); 2633 bool irq_auto_save_p = ((irq_ctrl_saved.irq_save_last_reg >= regno) 2634 && ARC_AUTO_IRQ_P (fn_type)); 2635 bool firq_auto_save_p = ARC_FAST_INTERRUPT_P (fn_type); 2636 2637 switch (rgf_banked_register_count) 2638 { 2639 case 4: 2640 firq_auto_save_p &= (regno < 4); 2641 break; 2642 case 8: 2643 firq_auto_save_p &= ((regno < 4) || ((regno > 11) && (regno < 16))); 2644 break; 2645 case 16: 2646 firq_auto_save_p &= ((regno < 4) || ((regno > 9) && (regno < 16)) 2647 || ((regno > 25) && (regno < 29)) 2648 || ((regno > 29) && (regno < 32))); 2649 break; 2650 case 32: 2651 firq_auto_save_p &= (regno != 29) && (regno < 32); 2652 break; 2653 default: 2654 firq_auto_save_p = false; 2655 break; 2656 } 2657 2658 if ((regno) != RETURN_ADDR_REGNUM 2659 && (regno) != FRAME_POINTER_REGNUM 2660 && df_regs_ever_live_p (regno) 2661 && (!call_used_regs[regno] 2662 || ARC_INTERRUPT_P (fn_type)) 2663 /* Do not emit code for auto saved regs. */ 2664 && !irq_auto_save_p 2665 && !firq_auto_save_p) 2666 return true; 2667 2668 return false; 2669 } 2670 2671 /* Return true if the return address must be saved in the current function, 2672 otherwise return false. */ 2673 2674 static bool 2675 arc_must_save_return_addr (struct function *func) 2676 { 2677 if (func->machine->frame_info.save_return_addr) 2678 return true; 2679 2680 return false; 2681 } 2682 2683 /* Helper function to wrap FRAME_POINTER_NEEDED. We do this as 2684 FRAME_POINTER_NEEDED will not be true until the IRA (Integrated 2685 Register Allocator) pass, while we want to get the frame size 2686 correct earlier than the IRA pass. 2687 2688 When a function uses eh_return we must ensure that the fp register 2689 is saved and then restored so that the unwinder can restore the 2690 correct value for the frame we are going to jump to. 2691 2692 To do this we force all frames that call eh_return to require a 2693 frame pointer (see arc_frame_pointer_required), this 2694 will ensure that the previous frame pointer is stored on entry to 2695 the function, and will then be reloaded at function exit. 2696 2697 As the frame pointer is handled as a special case in our prologue 2698 and epilogue code it must not be saved and restored using the 2699 MUST_SAVE_REGISTER mechanism otherwise we run into issues where GCC 2700 believes that the function is not using a frame pointer and that 2701 the value in the fp register is the frame pointer, while the 2702 prologue and epilogue are busy saving and restoring the fp 2703 register. 2704 2705 During compilation of a function the frame size is evaluated 2706 multiple times, it is not until the reload pass is complete the the 2707 frame size is considered fixed (it is at this point that space for 2708 all spills has been allocated). However the frame_pointer_needed 2709 variable is not set true until the register allocation pass, as a 2710 result in the early stages the frame size does not include space 2711 for the frame pointer to be spilled. 2712 2713 The problem that this causes is that the rtl generated for 2714 EH_RETURN_HANDLER_RTX uses the details of the frame size to compute 2715 the offset from the frame pointer at which the return address 2716 lives. However, in early passes GCC has not yet realised we need a 2717 frame pointer, and so has not included space for the frame pointer 2718 in the frame size, and so gets the offset of the return address 2719 wrong. This should not be an issue as in later passes GCC has 2720 realised that the frame pointer needs to be spilled, and has 2721 increased the frame size. However, the rtl for the 2722 EH_RETURN_HANDLER_RTX is not regenerated to use the newer, larger 2723 offset, and the wrong smaller offset is used. */ 2724 2725 static bool 2726 arc_frame_pointer_needed (void) 2727 { 2728 return (frame_pointer_needed || crtl->calls_eh_return); 2729 } 2730 2731 /* Return non-zero if there are registers to be saved or loaded using 2732 millicode thunks. We can only use consecutive sequences starting 2733 with r13, and not going beyond r25. 2734 GMASK is a bitmask of registers to save. This function sets 2735 FRAME->millicod_start_reg .. FRAME->millicode_end_reg to the range 2736 of registers to be saved / restored with a millicode call. */ 2737 2738 static int 2739 arc_compute_millicode_save_restore_regs (unsigned int gmask, 2740 struct arc_frame_info *frame) 2741 { 2742 int regno; 2743 2744 int start_reg = 13, end_reg = 25; 2745 2746 for (regno = start_reg; regno <= end_reg && (gmask & (1L << regno));) 2747 regno++; 2748 end_reg = regno - 1; 2749 /* There is no point in using millicode thunks if we don't save/restore 2750 at least three registers. For non-leaf functions we also have the 2751 blink restore. */ 2752 if (regno - start_reg >= 3 - (crtl->is_leaf == 0)) 2753 { 2754 frame->millicode_start_reg = 13; 2755 frame->millicode_end_reg = regno - 1; 2756 return 1; 2757 } 2758 return 0; 2759 } 2760 2761 /* Return the bytes needed to compute the frame pointer from the 2762 current stack pointer. */ 2763 2764 static unsigned int 2765 arc_compute_frame_size (void) 2766 { 2767 int regno; 2768 unsigned int total_size, var_size, args_size, pretend_size, extra_size; 2769 unsigned int reg_size, reg_offset; 2770 unsigned int gmask; 2771 struct arc_frame_info *frame_info; 2772 int size; 2773 2774 /* The answer might already be known. */ 2775 if (cfun->machine->frame_info.initialized) 2776 return cfun->machine->frame_info.total_size; 2777 2778 frame_info = &cfun->machine->frame_info; 2779 size = ARC_STACK_ALIGN (get_frame_size ()); 2780 2781 /* 1) Size of locals and temporaries. */ 2782 var_size = size; 2783 2784 /* 2) Size of outgoing arguments. */ 2785 args_size = crtl->outgoing_args_size; 2786 2787 /* 3) Calculate space needed for saved registers. 2788 ??? We ignore the extension registers for now. */ 2789 2790 /* See if this is an interrupt handler. Call used registers must be saved 2791 for them too. */ 2792 2793 reg_size = 0; 2794 gmask = 0; 2795 2796 for (regno = 0; regno <= 31; regno++) 2797 { 2798 if (arc_must_save_register (regno, cfun)) 2799 { 2800 reg_size += UNITS_PER_WORD; 2801 gmask |= 1L << regno; 2802 } 2803 } 2804 2805 /* In a frame that calls __builtin_eh_return two data registers are 2806 used to pass values back to the exception handler. 2807 2808 Ensure that these registers are spilled to the stack so that the 2809 exception throw code can find them, and update the saved values. 2810 The handling code will then consume these reloaded values to 2811 handle the exception. */ 2812 if (crtl->calls_eh_return) 2813 for (regno = 0; EH_RETURN_DATA_REGNO (regno) != INVALID_REGNUM; regno++) 2814 { 2815 reg_size += UNITS_PER_WORD; 2816 gmask |= 1 << regno; 2817 } 2818 2819 /* 4) Space for back trace data structure. 2820 <return addr reg size> (if required) + <fp size> (if required). */ 2821 frame_info->save_return_addr 2822 = (!crtl->is_leaf || df_regs_ever_live_p (RETURN_ADDR_REGNUM) 2823 || crtl->calls_eh_return); 2824 /* Saving blink reg in case of leaf function for millicode thunk calls. */ 2825 if (optimize_size 2826 && !TARGET_NO_MILLICODE_THUNK_SET 2827 && !crtl->calls_eh_return) 2828 { 2829 if (arc_compute_millicode_save_restore_regs (gmask, frame_info)) 2830 frame_info->save_return_addr = true; 2831 } 2832 2833 extra_size = 0; 2834 if (arc_must_save_return_addr (cfun)) 2835 extra_size = 4; 2836 if (arc_frame_pointer_needed ()) 2837 extra_size += 4; 2838 2839 /* 5) Space for variable arguments passed in registers */ 2840 pretend_size = crtl->args.pretend_args_size; 2841 2842 /* Ensure everything before the locals is aligned appropriately. */ 2843 { 2844 unsigned int extra_plus_reg_size; 2845 unsigned int extra_plus_reg_size_aligned; 2846 2847 extra_plus_reg_size = extra_size + reg_size; 2848 extra_plus_reg_size_aligned = ARC_STACK_ALIGN(extra_plus_reg_size); 2849 reg_size = extra_plus_reg_size_aligned - extra_size; 2850 } 2851 2852 /* Compute total frame size. */ 2853 total_size = var_size + args_size + extra_size + pretend_size + reg_size; 2854 2855 /* It used to be the case that the alignment was forced at this 2856 point. However, that is dangerous, calculations based on 2857 total_size would be wrong. Given that this has never cropped up 2858 as an issue I've changed this to an assert for now. */ 2859 gcc_assert (total_size == ARC_STACK_ALIGN (total_size)); 2860 2861 /* Compute offset of register save area from stack pointer: 2862 Frame: pretend_size <blink> reg_size <fp> var_size args_size <--sp 2863 */ 2864 reg_offset = (total_size - (pretend_size + reg_size + extra_size) 2865 + (arc_frame_pointer_needed () ? 4 : 0)); 2866 2867 /* Save computed information. */ 2868 frame_info->total_size = total_size; 2869 frame_info->extra_size = extra_size; 2870 frame_info->pretend_size = pretend_size; 2871 frame_info->var_size = var_size; 2872 frame_info->args_size = args_size; 2873 frame_info->reg_size = reg_size; 2874 frame_info->reg_offset = reg_offset; 2875 frame_info->gmask = gmask; 2876 frame_info->initialized = reload_completed; 2877 2878 /* Ok, we're done. */ 2879 return total_size; 2880 } 2881 2882 /* Common code to save/restore registers. */ 2883 /* BASE_REG is the base register to use for addressing and to adjust. 2884 GMASK is a bitmask of general purpose registers to save/restore. 2885 epilogue_p 0: prologue 1:epilogue 2:epilogue, sibling thunk 2886 If *FIRST_OFFSET is non-zero, add it first to BASE_REG - preferably 2887 using a pre-modify for the first memory access. *FIRST_OFFSET is then 2888 zeroed. */ 2889 2890 static void 2891 arc_save_restore (rtx base_reg, 2892 unsigned int gmask, int epilogue_p, int *first_offset) 2893 { 2894 unsigned int offset = 0; 2895 int regno; 2896 struct arc_frame_info *frame = &cfun->machine->frame_info; 2897 rtx sibthunk_insn = NULL_RTX; 2898 2899 if (gmask) 2900 { 2901 /* Millicode thunks implementation: 2902 Generates calls to millicodes for registers starting from r13 to r25 2903 Present Limitations: 2904 - Only one range supported. The remaining regs will have the ordinary 2905 st and ld instructions for store and loads. Hence a gmask asking 2906 to store r13-14, r16-r25 will only generate calls to store and 2907 load r13 to r14 while store and load insns will be generated for 2908 r16 to r25 in the prologue and epilogue respectively. 2909 2910 - Presently library only supports register ranges starting from r13. 2911 */ 2912 if (epilogue_p == 2 || frame->millicode_end_reg > 14) 2913 { 2914 int start_call = frame->millicode_start_reg; 2915 int end_call = frame->millicode_end_reg; 2916 int n_regs = end_call - start_call + 1; 2917 int i = 0, r, off = 0; 2918 rtx insn; 2919 rtx ret_addr = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM); 2920 2921 if (*first_offset) 2922 { 2923 /* "reg_size" won't be more than 127 . */ 2924 gcc_assert (epilogue_p || abs (*first_offset) <= 127); 2925 frame_add (base_reg, *first_offset); 2926 *first_offset = 0; 2927 } 2928 insn = gen_rtx_PARALLEL 2929 (VOIDmode, rtvec_alloc ((epilogue_p == 2) + n_regs + 1)); 2930 if (epilogue_p == 2) 2931 i += 2; 2932 else 2933 XVECEXP (insn, 0, n_regs) = gen_rtx_CLOBBER (VOIDmode, ret_addr); 2934 for (r = start_call; r <= end_call; r++, off += UNITS_PER_WORD, i++) 2935 { 2936 rtx reg = gen_rtx_REG (SImode, r); 2937 rtx mem 2938 = gen_frame_mem (SImode, plus_constant (Pmode, base_reg, off)); 2939 2940 if (epilogue_p) 2941 XVECEXP (insn, 0, i) = gen_rtx_SET (reg, mem); 2942 else 2943 XVECEXP (insn, 0, i) = gen_rtx_SET (mem, reg); 2944 gmask = gmask & ~(1L << r); 2945 } 2946 if (epilogue_p == 2) 2947 sibthunk_insn = insn; 2948 else 2949 { 2950 insn = frame_insn (insn); 2951 for (r = start_call, off = 0; 2952 r <= end_call; 2953 r++, off += UNITS_PER_WORD) 2954 { 2955 rtx reg = gen_rtx_REG (SImode, r); 2956 if (epilogue_p) 2957 add_reg_note (insn, REG_CFA_RESTORE, reg); 2958 else 2959 { 2960 rtx mem = gen_rtx_MEM (SImode, plus_constant (Pmode, 2961 base_reg, 2962 off)); 2963 2964 add_reg_note (insn, REG_CFA_OFFSET, 2965 gen_rtx_SET (mem, reg)); 2966 } 2967 } 2968 } 2969 offset += off; 2970 } 2971 2972 for (regno = 0; regno <= 31; regno++) 2973 { 2974 machine_mode mode = SImode; 2975 bool found = false; 2976 2977 if (TARGET_LL64 2978 && (regno % 2 == 0) 2979 && ((gmask & (1L << regno)) != 0) 2980 && ((gmask & (1L << (regno+1))) != 0)) 2981 { 2982 found = true; 2983 mode = DImode; 2984 } 2985 else if ((gmask & (1L << regno)) != 0) 2986 { 2987 found = true; 2988 mode = SImode; 2989 } 2990 2991 if (found) 2992 { 2993 rtx reg = gen_rtx_REG (mode, regno); 2994 rtx addr, mem; 2995 int cfa_adjust = *first_offset; 2996 2997 if (*first_offset) 2998 { 2999 gcc_assert (!offset); 3000 addr = plus_constant (Pmode, base_reg, *first_offset); 3001 addr = gen_rtx_PRE_MODIFY (Pmode, base_reg, addr); 3002 *first_offset = 0; 3003 } 3004 else 3005 { 3006 gcc_assert (SMALL_INT (offset)); 3007 addr = plus_constant (Pmode, base_reg, offset); 3008 } 3009 mem = gen_frame_mem (mode, addr); 3010 if (epilogue_p) 3011 { 3012 rtx insn = 3013 frame_move_inc (reg, mem, base_reg, addr); 3014 add_reg_note (insn, REG_CFA_RESTORE, reg); 3015 if (cfa_adjust) 3016 { 3017 enum reg_note note = REG_CFA_ADJUST_CFA; 3018 add_reg_note (insn, note, 3019 gen_rtx_SET (stack_pointer_rtx, 3020 plus_constant (Pmode, 3021 stack_pointer_rtx, 3022 cfa_adjust))); 3023 } 3024 } 3025 else 3026 frame_move_inc (mem, reg, base_reg, addr); 3027 offset += UNITS_PER_WORD; 3028 if (mode == DImode) 3029 { 3030 offset += UNITS_PER_WORD; 3031 ++regno; 3032 } 3033 } /* if */ 3034 } /* for */ 3035 }/* if */ 3036 if (sibthunk_insn) 3037 { 3038 int start_call = frame->millicode_start_reg; 3039 int end_call = frame->millicode_end_reg; 3040 int r; 3041 3042 rtx r12 = gen_rtx_REG (Pmode, 12); 3043 3044 frame_insn (gen_rtx_SET (r12, GEN_INT (offset))); 3045 XVECEXP (sibthunk_insn, 0, 0) = ret_rtx; 3046 XVECEXP (sibthunk_insn, 0, 1) 3047 = gen_rtx_SET (stack_pointer_rtx, 3048 gen_rtx_PLUS (Pmode, stack_pointer_rtx, r12)); 3049 sibthunk_insn = emit_jump_insn (sibthunk_insn); 3050 RTX_FRAME_RELATED_P (sibthunk_insn) = 1; 3051 3052 /* Would be nice if we could do this earlier, when the PARALLEL 3053 is populated, but these need to be attached after the 3054 emit. */ 3055 for (r = start_call; r <= end_call; r++) 3056 { 3057 rtx reg = gen_rtx_REG (SImode, r); 3058 add_reg_note (sibthunk_insn, REG_CFA_RESTORE, reg); 3059 } 3060 } 3061 } /* arc_save_restore */ 3062 3063 /* Build dwarf information when the context is saved via AUX_IRQ_CTRL 3064 mechanism. */ 3065 3066 static void 3067 arc_dwarf_emit_irq_save_regs (void) 3068 { 3069 rtx tmp, par, insn, reg; 3070 int i, offset, j; 3071 3072 par = gen_rtx_SEQUENCE (VOIDmode, 3073 rtvec_alloc (irq_ctrl_saved.irq_save_last_reg + 1 3074 + irq_ctrl_saved.irq_save_blink 3075 + irq_ctrl_saved.irq_save_lpcount 3076 + 1)); 3077 3078 /* Build the stack adjustment note for unwind info. */ 3079 j = 0; 3080 offset = UNITS_PER_WORD * (irq_ctrl_saved.irq_save_last_reg + 1 3081 + irq_ctrl_saved.irq_save_blink 3082 + irq_ctrl_saved.irq_save_lpcount); 3083 tmp = plus_constant (Pmode, stack_pointer_rtx, -1 * offset); 3084 tmp = gen_rtx_SET (stack_pointer_rtx, tmp); 3085 RTX_FRAME_RELATED_P (tmp) = 1; 3086 XVECEXP (par, 0, j++) = tmp; 3087 3088 offset -= UNITS_PER_WORD; 3089 3090 /* 1st goes LP_COUNT. */ 3091 if (irq_ctrl_saved.irq_save_lpcount) 3092 { 3093 reg = gen_rtx_REG (SImode, 60); 3094 tmp = plus_constant (Pmode, stack_pointer_rtx, offset); 3095 tmp = gen_frame_mem (SImode, tmp); 3096 tmp = gen_rtx_SET (tmp, reg); 3097 RTX_FRAME_RELATED_P (tmp) = 1; 3098 XVECEXP (par, 0, j++) = tmp; 3099 offset -= UNITS_PER_WORD; 3100 } 3101 3102 /* 2nd goes BLINK. */ 3103 if (irq_ctrl_saved.irq_save_blink) 3104 { 3105 reg = gen_rtx_REG (SImode, 31); 3106 tmp = plus_constant (Pmode, stack_pointer_rtx, offset); 3107 tmp = gen_frame_mem (SImode, tmp); 3108 tmp = gen_rtx_SET (tmp, reg); 3109 RTX_FRAME_RELATED_P (tmp) = 1; 3110 XVECEXP (par, 0, j++) = tmp; 3111 offset -= UNITS_PER_WORD; 3112 } 3113 3114 /* Build the parallel of the remaining registers recorded as saved 3115 for unwind. */ 3116 for (i = irq_ctrl_saved.irq_save_last_reg; i >= 0; i--) 3117 { 3118 reg = gen_rtx_REG (SImode, i); 3119 tmp = plus_constant (Pmode, stack_pointer_rtx, offset); 3120 tmp = gen_frame_mem (SImode, tmp); 3121 tmp = gen_rtx_SET (tmp, reg); 3122 RTX_FRAME_RELATED_P (tmp) = 1; 3123 XVECEXP (par, 0, j++) = tmp; 3124 offset -= UNITS_PER_WORD; 3125 } 3126 3127 /* Dummy insn used to anchor the dwarf info. */ 3128 insn = emit_insn (gen_stack_irq_dwarf()); 3129 add_reg_note (insn, REG_FRAME_RELATED_EXPR, par); 3130 RTX_FRAME_RELATED_P (insn) = 1; 3131 } 3132 3133 /* Set up the stack and frame pointer (if desired) for the function. */ 3134 3135 void 3136 arc_expand_prologue (void) 3137 { 3138 int size; 3139 unsigned int gmask = cfun->machine->frame_info.gmask; 3140 /* unsigned int frame_pointer_offset;*/ 3141 unsigned int frame_size_to_allocate; 3142 /* (FIXME: The first store will use a PRE_MODIFY; this will usually be r13. 3143 Change the stack layout so that we rather store a high register with the 3144 PRE_MODIFY, thus enabling more short insn generation.) */ 3145 int first_offset = 0; 3146 unsigned int fn_type = arc_compute_function_type (cfun); 3147 3148 /* Naked functions don't have prologue. */ 3149 if (ARC_NAKED_P (fn_type)) 3150 { 3151 if (flag_stack_usage_info) 3152 current_function_static_stack_size = 0; 3153 return; 3154 } 3155 3156 /* Compute total frame size. */ 3157 size = arc_compute_frame_size (); 3158 3159 if (flag_stack_usage_info) 3160 current_function_static_stack_size = size; 3161 3162 /* Keep track of frame size to be allocated. */ 3163 frame_size_to_allocate = size; 3164 3165 /* These cases shouldn't happen. Catch them now. */ 3166 gcc_assert (!(size == 0 && gmask)); 3167 3168 /* Allocate space for register arguments if this is a variadic function. */ 3169 if (cfun->machine->frame_info.pretend_size != 0) 3170 { 3171 /* Ensure pretend_size is maximum of 8 * word_size. */ 3172 gcc_assert (cfun->machine->frame_info.pretend_size <= 32); 3173 3174 frame_stack_add (-(HOST_WIDE_INT)cfun->machine->frame_info.pretend_size); 3175 frame_size_to_allocate -= cfun->machine->frame_info.pretend_size; 3176 } 3177 3178 /* IRQ using automatic save mechanism will save the register before 3179 anything we do. */ 3180 if (ARC_AUTO_IRQ_P (fn_type) 3181 && !ARC_FAST_INTERRUPT_P (fn_type)) 3182 { 3183 arc_dwarf_emit_irq_save_regs (); 3184 } 3185 3186 /* The home-grown ABI says link register is saved first. */ 3187 if (arc_must_save_return_addr (cfun) 3188 && !ARC_AUTOBLINK_IRQ_P (fn_type)) 3189 { 3190 rtx ra = gen_rtx_REG (SImode, RETURN_ADDR_REGNUM); 3191 rtx mem = gen_frame_mem (Pmode, 3192 gen_rtx_PRE_DEC (Pmode, 3193 stack_pointer_rtx)); 3194 3195 frame_move_inc (mem, ra, stack_pointer_rtx, 0); 3196 frame_size_to_allocate -= UNITS_PER_WORD; 3197 } 3198 3199 /* Save any needed call-saved regs (and call-used if this is an 3200 interrupt handler) for ARCompact ISA. */ 3201 if (cfun->machine->frame_info.reg_size) 3202 { 3203 first_offset = -cfun->machine->frame_info.reg_size; 3204 /* N.B. FRAME_POINTER_MASK and RETURN_ADDR_MASK are cleared in gmask. */ 3205 arc_save_restore (stack_pointer_rtx, gmask, 0, &first_offset); 3206 frame_size_to_allocate -= cfun->machine->frame_info.reg_size; 3207 } 3208 3209 /* In the case of millicode thunk, we need to restore the clobbered 3210 blink register. */ 3211 if (cfun->machine->frame_info.millicode_end_reg > 0 3212 && arc_must_save_return_addr (cfun)) 3213 { 3214 HOST_WIDE_INT tmp = cfun->machine->frame_info.reg_size; 3215 emit_insn (gen_rtx_SET (gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM), 3216 gen_rtx_MEM (Pmode, 3217 plus_constant (Pmode, 3218 stack_pointer_rtx, 3219 tmp)))); 3220 } 3221 3222 /* Save frame pointer if needed. First save the FP on stack, if not 3223 autosaved. */ 3224 if (arc_frame_pointer_needed () 3225 && !ARC_AUTOFP_IRQ_P (fn_type)) 3226 { 3227 rtx addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, 3228 GEN_INT (-UNITS_PER_WORD + first_offset)); 3229 rtx mem = gen_frame_mem (Pmode, gen_rtx_PRE_MODIFY (Pmode, 3230 stack_pointer_rtx, 3231 addr)); 3232 frame_move_inc (mem, frame_pointer_rtx, stack_pointer_rtx, 0); 3233 frame_size_to_allocate -= UNITS_PER_WORD; 3234 first_offset = 0; 3235 } 3236 3237 /* Emit mov fp,sp. */ 3238 if (arc_frame_pointer_needed ()) 3239 { 3240 frame_move (frame_pointer_rtx, stack_pointer_rtx); 3241 } 3242 3243 /* ??? We don't handle the case where the saved regs are more than 252 3244 bytes away from sp. This can be handled by decrementing sp once, saving 3245 the regs, and then decrementing it again. The epilogue doesn't have this 3246 problem as the `ld' insn takes reg+limm values (though it would be more 3247 efficient to avoid reg+limm). */ 3248 3249 frame_size_to_allocate -= first_offset; 3250 /* Allocate the stack frame. */ 3251 if (frame_size_to_allocate > 0) 3252 { 3253 frame_stack_add ((HOST_WIDE_INT) 0 - frame_size_to_allocate); 3254 /* If the frame pointer is needed, emit a special barrier that 3255 will prevent the scheduler from moving stores to the frame 3256 before the stack adjustment. */ 3257 if (arc_frame_pointer_needed ()) 3258 emit_insn (gen_stack_tie (stack_pointer_rtx, 3259 hard_frame_pointer_rtx)); 3260 } 3261 } 3262 3263 /* Do any necessary cleanup after a function to restore stack, frame, 3264 and regs. */ 3265 3266 void 3267 arc_expand_epilogue (int sibcall_p) 3268 { 3269 int size; 3270 unsigned int fn_type = arc_compute_function_type (cfun); 3271 3272 size = arc_compute_frame_size (); 3273 3274 unsigned int pretend_size = cfun->machine->frame_info.pretend_size; 3275 unsigned int frame_size; 3276 unsigned int size_to_deallocate; 3277 int restored; 3278 int can_trust_sp_p = !cfun->calls_alloca; 3279 int first_offset = 0; 3280 int millicode_p = cfun->machine->frame_info.millicode_end_reg > 0; 3281 rtx insn; 3282 3283 /* Naked functions don't have epilogue. */ 3284 if (ARC_NAKED_P (fn_type)) 3285 return; 3286 3287 size_to_deallocate = size; 3288 3289 frame_size = size - (pretend_size + 3290 cfun->machine->frame_info.reg_size + 3291 cfun->machine->frame_info.extra_size); 3292 3293 /* ??? There are lots of optimizations that can be done here. 3294 EG: Use fp to restore regs if it's closer. 3295 Maybe in time we'll do them all. For now, always restore regs from 3296 sp, but don't restore sp if we don't have to. */ 3297 3298 if (!can_trust_sp_p) 3299 gcc_assert (arc_frame_pointer_needed ()); 3300 3301 /* Restore stack pointer to the beginning of saved register area for 3302 ARCompact ISA. */ 3303 if (frame_size) 3304 { 3305 if (arc_frame_pointer_needed ()) 3306 frame_move (stack_pointer_rtx, frame_pointer_rtx); 3307 else 3308 first_offset = frame_size; 3309 size_to_deallocate -= frame_size; 3310 } 3311 else if (!can_trust_sp_p) 3312 frame_stack_add (-frame_size); 3313 3314 3315 /* Restore any saved registers. */ 3316 if (arc_frame_pointer_needed () 3317 && !ARC_AUTOFP_IRQ_P (fn_type)) 3318 { 3319 rtx addr = gen_rtx_POST_INC (Pmode, stack_pointer_rtx); 3320 3321 insn = frame_move_inc (frame_pointer_rtx, gen_frame_mem (Pmode, addr), 3322 stack_pointer_rtx, 0); 3323 add_reg_note (insn, REG_CFA_RESTORE, frame_pointer_rtx); 3324 add_reg_note (insn, REG_CFA_DEF_CFA, 3325 plus_constant (SImode, stack_pointer_rtx, 3326 4)); 3327 size_to_deallocate -= UNITS_PER_WORD; 3328 } 3329 3330 /* Load blink after the calls to thunk calls in case of optimize size. */ 3331 if (millicode_p) 3332 { 3333 int sibthunk_p = (!sibcall_p 3334 && fn_type == ARC_FUNCTION_NORMAL 3335 && !cfun->machine->frame_info.pretend_size); 3336 3337 gcc_assert (!(cfun->machine->frame_info.gmask 3338 & (FRAME_POINTER_MASK | RETURN_ADDR_MASK))); 3339 arc_save_restore (stack_pointer_rtx, 3340 cfun->machine->frame_info.gmask, 3341 1 + sibthunk_p, &first_offset); 3342 if (sibthunk_p) 3343 return; 3344 } 3345 /* If we are to restore registers, and first_offset would require 3346 a limm to be encoded in a PRE_MODIFY, yet we can add it with a 3347 fast add to the stack pointer, do this now. */ 3348 if ((!SMALL_INT (first_offset) 3349 && cfun->machine->frame_info.gmask 3350 && ((TARGET_ARC700 && !optimize_size) 3351 ? first_offset <= 0x800 3352 : satisfies_constraint_C2a (GEN_INT (first_offset)))) 3353 /* Also do this if we have both gprs and return 3354 address to restore, and they both would need a LIMM. */ 3355 || (arc_must_save_return_addr (cfun) 3356 && !SMALL_INT ((cfun->machine->frame_info.reg_size + first_offset) >> 2) 3357 && cfun->machine->frame_info.gmask)) 3358 { 3359 frame_stack_add (first_offset); 3360 first_offset = 0; 3361 } 3362 if (arc_must_save_return_addr (cfun) 3363 && !ARC_AUTOBLINK_IRQ_P (fn_type)) 3364 { 3365 rtx ra = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM); 3366 int ra_offs = cfun->machine->frame_info.reg_size + first_offset; 3367 rtx addr = plus_constant (Pmode, stack_pointer_rtx, ra_offs); 3368 HOST_WIDE_INT cfa_adjust = 0; 3369 3370 /* If the load of blink would need a LIMM, but we can add 3371 the offset quickly to sp, do the latter. */ 3372 if (!SMALL_INT (ra_offs >> 2) 3373 && !cfun->machine->frame_info.gmask 3374 && ((TARGET_ARC700 && !optimize_size) 3375 ? ra_offs <= 0x800 3376 : satisfies_constraint_C2a (GEN_INT (ra_offs)))) 3377 { 3378 size_to_deallocate -= ra_offs - first_offset; 3379 first_offset = 0; 3380 frame_stack_add (ra_offs); 3381 ra_offs = 0; 3382 addr = stack_pointer_rtx; 3383 } 3384 /* See if we can combine the load of the return address with the 3385 final stack adjustment. 3386 We need a separate load if there are still registers to 3387 restore. We also want a separate load if the combined insn 3388 would need a limm, but a separate load doesn't. */ 3389 if (ra_offs 3390 && !cfun->machine->frame_info.gmask 3391 && (SMALL_INT (ra_offs) || !SMALL_INT (ra_offs >> 2))) 3392 { 3393 addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, addr); 3394 cfa_adjust = ra_offs; 3395 first_offset = 0; 3396 size_to_deallocate -= cfun->machine->frame_info.reg_size; 3397 } 3398 else if (!ra_offs && size_to_deallocate == UNITS_PER_WORD) 3399 { 3400 addr = gen_rtx_POST_INC (Pmode, addr); 3401 cfa_adjust = GET_MODE_SIZE (Pmode); 3402 size_to_deallocate = 0; 3403 } 3404 3405 insn = frame_move_inc (ra, gen_frame_mem (Pmode, addr), 3406 stack_pointer_rtx, addr); 3407 if (cfa_adjust) 3408 { 3409 enum reg_note note = REG_CFA_ADJUST_CFA; 3410 3411 add_reg_note (insn, note, 3412 gen_rtx_SET (stack_pointer_rtx, 3413 plus_constant (SImode, stack_pointer_rtx, 3414 cfa_adjust))); 3415 } 3416 add_reg_note (insn, REG_CFA_RESTORE, ra); 3417 } 3418 3419 if (!millicode_p) 3420 { 3421 if (cfun->machine->frame_info.reg_size) 3422 arc_save_restore (stack_pointer_rtx, 3423 /* The zeroing of these two bits is unnecessary, but leave this in for clarity. */ 3424 cfun->machine->frame_info.gmask 3425 & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK), 1, &first_offset); 3426 } 3427 3428 /* The rest of this function does the following: 3429 ARCompact : handle epilogue_delay, restore sp (phase-2), return 3430 */ 3431 3432 /* Keep track of how much of the stack pointer we've restored. 3433 It makes the following a lot more readable. */ 3434 size_to_deallocate += first_offset; 3435 restored = size - size_to_deallocate; 3436 3437 if (size > restored) 3438 frame_stack_add (size - restored); 3439 3440 /* For frames that use __builtin_eh_return, the register defined by 3441 EH_RETURN_STACKADJ_RTX is set to 0 for all standard return paths. 3442 On eh_return paths however, the register is set to the value that 3443 should be added to the stack pointer in order to restore the 3444 correct stack pointer for the exception handling frame. 3445 3446 For ARC we are going to use r2 for EH_RETURN_STACKADJ_RTX, add 3447 this onto the stack for eh_return frames. */ 3448 if (crtl->calls_eh_return) 3449 emit_insn (gen_add2_insn (stack_pointer_rtx, 3450 EH_RETURN_STACKADJ_RTX)); 3451 3452 /* Emit the return instruction. */ 3453 if (sibcall_p == FALSE) 3454 emit_jump_insn (gen_simple_return ()); 3455 } 3456 3457 /* Return rtx for the location of the return address on the stack, 3458 suitable for use in __builtin_eh_return. The new return address 3459 will be written to this location in order to redirect the return to 3460 the exception handler. Our ABI says the blink is pushed first on 3461 stack followed by an unknown number of register saves, and finally 3462 by fp. Hence we cannot use the EH_RETURN_ADDRESS macro as the 3463 stack is not finalized. */ 3464 3465 void 3466 arc_eh_return_address_location (rtx source) 3467 { 3468 rtx mem; 3469 int offset; 3470 struct arc_frame_info *afi; 3471 3472 arc_compute_frame_size (); 3473 afi = &cfun->machine->frame_info; 3474 3475 gcc_assert (crtl->calls_eh_return); 3476 gcc_assert (afi->save_return_addr); 3477 gcc_assert (afi->extra_size >= 4); 3478 3479 /* The '-4' removes the size of the return address, which is 3480 included in the 'extra_size' field. */ 3481 offset = afi->reg_size + afi->extra_size - 4; 3482 mem = gen_frame_mem (Pmode, 3483 plus_constant (Pmode, frame_pointer_rtx, offset)); 3484 3485 /* The following should not be needed, and is, really a hack. The 3486 issue being worked around here is that the DSE (Dead Store 3487 Elimination) pass will remove this write to the stack as it sees 3488 a single store and no corresponding read. The read however 3489 occurs in the epilogue code, which is not added into the function 3490 rtl until a later pass. So, at the time of DSE, the decision to 3491 remove this store seems perfectly sensible. Marking the memory 3492 address as volatile obviously has the effect of preventing DSE 3493 from removing the store. */ 3494 MEM_VOLATILE_P (mem) = true; 3495 emit_move_insn (mem, source); 3496 } 3497 3498 /* PIC */ 3499 3500 /* Helper to generate unspec constant. */ 3501 3502 static rtx 3503 arc_unspec_offset (rtx loc, int unspec) 3504 { 3505 return gen_rtx_CONST (Pmode, gen_rtx_UNSPEC (Pmode, gen_rtvec (1, loc), 3506 unspec)); 3507 } 3508 3509 /* !TARGET_BARREL_SHIFTER support. */ 3510 /* Emit a shift insn to set OP0 to OP1 shifted by OP2; CODE specifies what 3511 kind of shift. */ 3512 3513 void 3514 emit_shift (enum rtx_code code, rtx op0, rtx op1, rtx op2) 3515 { 3516 rtx shift = gen_rtx_fmt_ee (code, SImode, op1, op2); 3517 rtx pat 3518 = ((shift4_operator (shift, SImode) ? gen_shift_si3 : gen_shift_si3_loop) 3519 (op0, op1, op2, shift)); 3520 emit_insn (pat); 3521 } 3522 3523 /* Output the assembler code for doing a shift. 3524 We go to a bit of trouble to generate efficient code as the ARC601 only has 3525 single bit shifts. This is taken from the h8300 port. We only have one 3526 mode of shifting and can't access individual bytes like the h8300 can, so 3527 this is greatly simplified (at the expense of not generating hyper- 3528 efficient code). 3529 3530 This function is not used if the variable shift insns are present. */ 3531 3532 /* FIXME: This probably can be done using a define_split in arc.md. 3533 Alternately, generate rtx rather than output instructions. */ 3534 3535 const char * 3536 output_shift (rtx *operands) 3537 { 3538 /* static int loopend_lab;*/ 3539 rtx shift = operands[3]; 3540 machine_mode mode = GET_MODE (shift); 3541 enum rtx_code code = GET_CODE (shift); 3542 const char *shift_one; 3543 3544 gcc_assert (mode == SImode); 3545 3546 switch (code) 3547 { 3548 case ASHIFT: shift_one = "add %0,%1,%1"; break; 3549 case ASHIFTRT: shift_one = "asr %0,%1"; break; 3550 case LSHIFTRT: shift_one = "lsr %0,%1"; break; 3551 default: gcc_unreachable (); 3552 } 3553 3554 if (GET_CODE (operands[2]) != CONST_INT) 3555 { 3556 output_asm_insn ("and.f lp_count,%2, 0x1f", operands); 3557 goto shiftloop; 3558 } 3559 else 3560 { 3561 int n; 3562 3563 n = INTVAL (operands[2]); 3564 3565 /* Only consider the lower 5 bits of the shift count. */ 3566 n = n & 0x1f; 3567 3568 /* First see if we can do them inline. */ 3569 /* ??? We could get better scheduling & shorter code (using short insns) 3570 by using splitters. Alas, that'd be even more verbose. */ 3571 if (code == ASHIFT && n <= 9 && n > 2 3572 && dest_reg_operand (operands[4], SImode)) 3573 { 3574 output_asm_insn ("mov %4,0\n\tadd3 %0,%4,%1", operands); 3575 for (n -=3 ; n >= 3; n -= 3) 3576 output_asm_insn ("add3 %0,%4,%0", operands); 3577 if (n == 2) 3578 output_asm_insn ("add2 %0,%4,%0", operands); 3579 else if (n) 3580 output_asm_insn ("add %0,%0,%0", operands); 3581 } 3582 else if (n <= 4) 3583 { 3584 while (--n >= 0) 3585 { 3586 output_asm_insn (shift_one, operands); 3587 operands[1] = operands[0]; 3588 } 3589 } 3590 /* See if we can use a rotate/and. */ 3591 else if (n == BITS_PER_WORD - 1) 3592 { 3593 switch (code) 3594 { 3595 case ASHIFT : 3596 output_asm_insn ("and %0,%1,1\n\tror %0,%0", operands); 3597 break; 3598 case ASHIFTRT : 3599 /* The ARC doesn't have a rol insn. Use something else. */ 3600 output_asm_insn ("add.f 0,%1,%1\n\tsbc %0,%0,%0", operands); 3601 break; 3602 case LSHIFTRT : 3603 /* The ARC doesn't have a rol insn. Use something else. */ 3604 output_asm_insn ("add.f 0,%1,%1\n\trlc %0,0", operands); 3605 break; 3606 default: 3607 break; 3608 } 3609 } 3610 else if (n == BITS_PER_WORD - 2 && dest_reg_operand (operands[4], SImode)) 3611 { 3612 switch (code) 3613 { 3614 case ASHIFT : 3615 output_asm_insn ("and %0,%1,3\n\tror %0,%0\n\tror %0,%0", operands); 3616 break; 3617 case ASHIFTRT : 3618 #if 1 /* Need some scheduling comparisons. */ 3619 output_asm_insn ("add.f %4,%1,%1\n\tsbc %0,%0,%0\n\t" 3620 "add.f 0,%4,%4\n\trlc %0,%0", operands); 3621 #else 3622 output_asm_insn ("add.f %4,%1,%1\n\tbxor %0,%4,31\n\t" 3623 "sbc.f %0,%0,%4\n\trlc %0,%0", operands); 3624 #endif 3625 break; 3626 case LSHIFTRT : 3627 #if 1 3628 output_asm_insn ("add.f %4,%1,%1\n\trlc %0,0\n\t" 3629 "add.f 0,%4,%4\n\trlc %0,%0", operands); 3630 #else 3631 output_asm_insn ("add.f %0,%1,%1\n\trlc.f %0,0\n\t" 3632 "and %0,%0,1\n\trlc %0,%0", operands); 3633 #endif 3634 break; 3635 default: 3636 break; 3637 } 3638 } 3639 else if (n == BITS_PER_WORD - 3 && code == ASHIFT) 3640 output_asm_insn ("and %0,%1,7\n\tror %0,%0\n\tror %0,%0\n\tror %0,%0", 3641 operands); 3642 /* Must loop. */ 3643 else 3644 { 3645 operands[2] = GEN_INT (n); 3646 output_asm_insn ("mov.f lp_count, %2", operands); 3647 3648 shiftloop: 3649 { 3650 output_asm_insn ("lpnz\t2f", operands); 3651 output_asm_insn (shift_one, operands); 3652 output_asm_insn ("nop", operands); 3653 fprintf (asm_out_file, "2:\t%s end single insn loop\n", 3654 ASM_COMMENT_START); 3655 } 3656 } 3657 } 3658 3659 return ""; 3660 } 3661 3662 /* Nested function support. */ 3663 3664 /* Output assembler code for a block containing the constant parts of 3665 a trampoline, leaving space for variable parts. A trampoline looks 3666 like this: 3667 3668 ld_s r12,[pcl,8] 3669 ld r11,[pcl,12] 3670 j_s [r12] 3671 .word function's address 3672 .word static chain value 3673 3674 */ 3675 3676 static void 3677 arc_asm_trampoline_template (FILE *f) 3678 { 3679 asm_fprintf (f, "\tld_s\t%s,[pcl,8]\n", ARC_TEMP_SCRATCH_REG); 3680 asm_fprintf (f, "\tld\t%s,[pcl,12]\n", reg_names[STATIC_CHAIN_REGNUM]); 3681 asm_fprintf (f, "\tj_s\t[%s]\n", ARC_TEMP_SCRATCH_REG); 3682 assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); 3683 assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); 3684 } 3685 3686 /* Emit RTL insns to initialize the variable parts of a trampoline. 3687 FNADDR is an RTX for the address of the function's pure code. CXT 3688 is an RTX for the static chain value for the function. 3689 3690 The fastest trampoline to execute for trampolines within +-8KB of CTX 3691 would be: 3692 3693 add2 r11,pcl,s12 3694 j [limm] 0x20200f80 limm 3695 3696 and that would also be faster to write to the stack by computing 3697 the offset from CTX to TRAMP at compile time. However, it would 3698 really be better to get rid of the high cost of cache invalidation 3699 when generating trampolines, which requires that the code part of 3700 trampolines stays constant, and additionally either making sure 3701 that no executable code but trampolines is on the stack, no icache 3702 entries linger for the area of the stack from when before the stack 3703 was allocated, and allocating trampolines in trampoline-only cache 3704 lines or allocate trampolines fram a special pool of pre-allocated 3705 trampolines. */ 3706 3707 static void 3708 arc_initialize_trampoline (rtx tramp, tree fndecl, rtx cxt) 3709 { 3710 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0); 3711 3712 emit_block_move (tramp, assemble_trampoline_template (), 3713 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL); 3714 emit_move_insn (adjust_address (tramp, SImode, 8), fnaddr); 3715 emit_move_insn (adjust_address (tramp, SImode, 12), cxt); 3716 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"), 3717 LCT_NORMAL, VOIDmode, XEXP (tramp, 0), Pmode, 3718 plus_constant (Pmode, XEXP (tramp, 0), TRAMPOLINE_SIZE), 3719 Pmode); 3720 } 3721 3722 /* Add the given function declaration to emit code in JLI section. */ 3723 3724 static void 3725 arc_add_jli_section (rtx pat) 3726 { 3727 const char *name; 3728 tree attrs; 3729 arc_jli_section *sec = arc_jli_sections, *new_section; 3730 tree decl = SYMBOL_REF_DECL (pat); 3731 3732 if (!pat) 3733 return; 3734 3735 if (decl) 3736 { 3737 /* For fixed locations do not generate the jli table entry. It 3738 should be provided by the user as an asm file. */ 3739 attrs = TYPE_ATTRIBUTES (TREE_TYPE (decl)); 3740 if (lookup_attribute ("jli_fixed", attrs)) 3741 return; 3742 } 3743 3744 name = XSTR (pat, 0); 3745 3746 /* Don't insert the same symbol twice. */ 3747 while (sec != NULL) 3748 { 3749 if(strcmp (name, sec->name) == 0) 3750 return; 3751 sec = sec->next; 3752 } 3753 3754 /* New name, insert it. */ 3755 new_section = (arc_jli_section *) xmalloc (sizeof (arc_jli_section)); 3756 gcc_assert (new_section != NULL); 3757 new_section->name = name; 3758 new_section->next = arc_jli_sections; 3759 arc_jli_sections = new_section; 3760 } 3761 3762 /* This is set briefly to 1 when we output a ".as" address modifer, and then 3763 reset when we output the scaled address. */ 3764 static int output_scaled = 0; 3765 3766 /* Print operand X (an rtx) in assembler syntax to file FILE. 3767 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified. 3768 For `%' followed by punctuation, CODE is the punctuation and X is null. */ 3769 /* In final.c:output_asm_insn: 3770 'l' : label 3771 'a' : address 3772 'c' : constant address if CONSTANT_ADDRESS_P 3773 'n' : negative 3774 Here: 3775 'Z': log2(x+1)-1 3776 'z': log2 3777 'M': log2(~x) 3778 'p': bit Position of lsb 3779 's': size of bit field 3780 '#': condbranch delay slot suffix 3781 '*': jump delay slot suffix 3782 '?' : nonjump-insn suffix for conditional execution or short instruction 3783 '!' : jump / call suffix for conditional execution or short instruction 3784 '`': fold constant inside unary o-perator, re-recognize, and emit. 3785 'd' 3786 'D' 3787 'R': Second word 3788 'S': JLI instruction 3789 'j': used by mov instruction to properly emit jli related labels. 3790 'B': Branch comparison operand - suppress sda reference 3791 'H': Most significant word 3792 'L': Least significant word 3793 'A': ASCII decimal representation of floating point value 3794 'U': Load/store update or scaling indicator 3795 'V': cache bypass indicator for volatile 3796 'P' 3797 'F' 3798 '^' 3799 'O': Operator 3800 'o': original symbol - no @ prepending. */ 3801 3802 void 3803 arc_print_operand (FILE *file, rtx x, int code) 3804 { 3805 switch (code) 3806 { 3807 case 'Z': 3808 if (GET_CODE (x) == CONST_INT) 3809 fprintf (file, "%d",exact_log2(INTVAL (x) + 1) - 1 ); 3810 else 3811 output_operand_lossage ("invalid operand to %%Z code"); 3812 3813 return; 3814 3815 case 'z': 3816 if (GET_CODE (x) == CONST_INT) 3817 fprintf (file, "%d",exact_log2(INTVAL (x)) ); 3818 else 3819 output_operand_lossage ("invalid operand to %%z code"); 3820 3821 return; 3822 3823 case 'c': 3824 if (GET_CODE (x) == CONST_INT) 3825 fprintf (file, "%ld", INTVAL (x) ); 3826 else 3827 output_operand_lossage ("invalid operands to %%c code"); 3828 3829 return; 3830 3831 case 'M': 3832 if (GET_CODE (x) == CONST_INT) 3833 fprintf (file, "%d",exact_log2(~INTVAL (x)) ); 3834 else 3835 output_operand_lossage ("invalid operand to %%M code"); 3836 3837 return; 3838 3839 case 'p': 3840 if (GET_CODE (x) == CONST_INT) 3841 fprintf (file, "%d", exact_log2 (INTVAL (x) & -INTVAL (x))); 3842 else 3843 output_operand_lossage ("invalid operand to %%p code"); 3844 return; 3845 3846 case 's': 3847 if (GET_CODE (x) == CONST_INT) 3848 { 3849 HOST_WIDE_INT i = INTVAL (x); 3850 HOST_WIDE_INT s = exact_log2 (i & -i); 3851 fprintf (file, "%d", exact_log2 (((0xffffffffUL & i) >> s) + 1)); 3852 } 3853 else 3854 output_operand_lossage ("invalid operand to %%s code"); 3855 return; 3856 3857 case '#' : 3858 /* Conditional branches depending on condition codes. 3859 Note that this is only for branches that were known to depend on 3860 condition codes before delay slot scheduling; 3861 out-of-range brcc / bbit expansions should use '*'. 3862 This distinction is important because of the different 3863 allowable delay slot insns and the output of the delay suffix 3864 for TARGET_AT_DBR_COND_EXEC. */ 3865 case '*' : 3866 /* Unconditional branches / branches not depending on condition codes. 3867 This could also be a CALL_INSN. 3868 Output the appropriate delay slot suffix. */ 3869 if (final_sequence && final_sequence->len () != 1) 3870 { 3871 rtx_insn *jump = final_sequence->insn (0); 3872 rtx_insn *delay = final_sequence->insn (1); 3873 3874 /* For TARGET_PAD_RETURN we might have grabbed the delay insn. */ 3875 if (delay->deleted ()) 3876 return; 3877 if (JUMP_P (jump) && INSN_ANNULLED_BRANCH_P (jump)) 3878 fputs (INSN_FROM_TARGET_P (delay) ? ".d" 3879 : TARGET_AT_DBR_CONDEXEC && code == '#' ? ".d" 3880 : get_attr_type (jump) == TYPE_RETURN && code == '#' ? "" 3881 : ".nd", 3882 file); 3883 else 3884 fputs (".d", file); 3885 } 3886 return; 3887 case '?' : /* with leading "." */ 3888 case '!' : /* without leading "." */ 3889 /* This insn can be conditionally executed. See if the ccfsm machinery 3890 says it should be conditionalized. 3891 If it shouldn't, we'll check the compact attribute if this insn 3892 has a short variant, which may be used depending on code size and 3893 alignment considerations. */ 3894 if (current_insn_predicate) 3895 arc_ccfsm_current.cc 3896 = get_arc_condition_code (current_insn_predicate); 3897 if (ARC_CCFSM_COND_EXEC_P (&arc_ccfsm_current)) 3898 { 3899 /* Is this insn in a delay slot sequence? */ 3900 if (!final_sequence || XVECLEN (final_sequence, 0) < 2 3901 || current_insn_predicate 3902 || CALL_P (final_sequence->insn (0)) 3903 || simplejump_p (final_sequence->insn (0))) 3904 { 3905 /* This insn isn't in a delay slot sequence, or conditionalized 3906 independently of its position in a delay slot. */ 3907 fprintf (file, "%s%s", 3908 code == '?' ? "." : "", 3909 arc_condition_codes[arc_ccfsm_current.cc]); 3910 /* If this is a jump, there are still short variants. However, 3911 only beq_s / bne_s have the same offset range as b_s, 3912 and the only short conditional returns are jeq_s and jne_s. */ 3913 if (code == '!' 3914 && (arc_ccfsm_current.cc == ARC_CC_EQ 3915 || arc_ccfsm_current.cc == ARC_CC_NE 3916 || 0 /* FIXME: check if branch in 7 bit range. */)) 3917 output_short_suffix (file); 3918 } 3919 else if (code == '!') /* Jump with delay slot. */ 3920 fputs (arc_condition_codes[arc_ccfsm_current.cc], file); 3921 else /* An Instruction in a delay slot of a jump or call. */ 3922 { 3923 rtx jump = XVECEXP (final_sequence, 0, 0); 3924 rtx insn = XVECEXP (final_sequence, 0, 1); 3925 3926 /* If the insn is annulled and is from the target path, we need 3927 to inverse the condition test. */ 3928 if (JUMP_P (jump) && INSN_ANNULLED_BRANCH_P (jump)) 3929 { 3930 if (INSN_FROM_TARGET_P (insn)) 3931 fprintf (file, "%s%s", 3932 code == '?' ? "." : "", 3933 arc_condition_codes[ARC_INVERSE_CONDITION_CODE (arc_ccfsm_current.cc)]); 3934 else 3935 fprintf (file, "%s%s", 3936 code == '?' ? "." : "", 3937 arc_condition_codes[arc_ccfsm_current.cc]); 3938 if (arc_ccfsm_current.state == 5) 3939 arc_ccfsm_current.state = 0; 3940 } 3941 else 3942 /* This insn is executed for either path, so don't 3943 conditionalize it at all. */ 3944 output_short_suffix (file); 3945 3946 } 3947 } 3948 else 3949 output_short_suffix (file); 3950 return; 3951 case'`': 3952 /* FIXME: fold constant inside unary operator, re-recognize, and emit. */ 3953 gcc_unreachable (); 3954 case 'd' : 3955 fputs (arc_condition_codes[get_arc_condition_code (x)], file); 3956 return; 3957 case 'D' : 3958 fputs (arc_condition_codes[ARC_INVERSE_CONDITION_CODE 3959 (get_arc_condition_code (x))], 3960 file); 3961 return; 3962 case 'R' : 3963 /* Write second word of DImode or DFmode reference, 3964 register or memory. */ 3965 if (GET_CODE (x) == REG) 3966 fputs (reg_names[REGNO (x)+1], file); 3967 else if (GET_CODE (x) == MEM) 3968 { 3969 fputc ('[', file); 3970 3971 /* Handle possible auto-increment. For PRE_INC / PRE_DEC / 3972 PRE_MODIFY, we will have handled the first word already; 3973 For POST_INC / POST_DEC / POST_MODIFY, the access to the 3974 first word will be done later. In either case, the access 3975 to the first word will do the modify, and we only have 3976 to add an offset of four here. */ 3977 if (GET_CODE (XEXP (x, 0)) == PRE_INC 3978 || GET_CODE (XEXP (x, 0)) == PRE_DEC 3979 || GET_CODE (XEXP (x, 0)) == PRE_MODIFY 3980 || GET_CODE (XEXP (x, 0)) == POST_INC 3981 || GET_CODE (XEXP (x, 0)) == POST_DEC 3982 || GET_CODE (XEXP (x, 0)) == POST_MODIFY) 3983 output_address (VOIDmode, 3984 plus_constant (Pmode, XEXP (XEXP (x, 0), 0), 4)); 3985 else if (output_scaled) 3986 { 3987 rtx addr = XEXP (x, 0); 3988 int size = GET_MODE_SIZE (GET_MODE (x)); 3989 3990 output_address (VOIDmode, 3991 plus_constant (Pmode, XEXP (addr, 0), 3992 ((INTVAL (XEXP (addr, 1)) + 4) 3993 >> (size == 2 ? 1 : 2)))); 3994 output_scaled = 0; 3995 } 3996 else 3997 output_address (VOIDmode, 3998 plus_constant (Pmode, XEXP (x, 0), 4)); 3999 fputc (']', file); 4000 } 4001 else 4002 output_operand_lossage ("invalid operand to %%R code"); 4003 return; 4004 case 'j': 4005 case 'S' : 4006 if (GET_CODE (x) == SYMBOL_REF 4007 && arc_is_jli_call_p (x)) 4008 { 4009 if (SYMBOL_REF_DECL (x)) 4010 { 4011 tree attrs = (TREE_TYPE (SYMBOL_REF_DECL (x)) != error_mark_node 4012 ? TYPE_ATTRIBUTES (TREE_TYPE (SYMBOL_REF_DECL (x))) 4013 : NULL_TREE); 4014 if (lookup_attribute ("jli_fixed", attrs)) 4015 { 4016 /* No special treatment for jli_fixed functions. */ 4017 if (code == 'j') 4018 break; 4019 fprintf (file, "%ld\t; @", 4020 TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attrs)))); 4021 assemble_name (file, XSTR (x, 0)); 4022 return; 4023 } 4024 } 4025 fprintf (file, "@__jli."); 4026 assemble_name (file, XSTR (x, 0)); 4027 if (code == 'j') 4028 arc_add_jli_section (x); 4029 return; 4030 } 4031 if (GET_CODE (x) == SYMBOL_REF 4032 && arc_is_secure_call_p (x)) 4033 { 4034 /* No special treatment for secure functions. */ 4035 if (code == 'j' ) 4036 break; 4037 tree attrs = (TREE_TYPE (SYMBOL_REF_DECL (x)) != error_mark_node 4038 ? TYPE_ATTRIBUTES (TREE_TYPE (SYMBOL_REF_DECL (x))) 4039 : NULL_TREE); 4040 fprintf (file, "%ld\t; @", 4041 TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attrs)))); 4042 assemble_name (file, XSTR (x, 0)); 4043 return; 4044 } 4045 break; 4046 case 'B' /* Branch or other LIMM ref - must not use sda references. */ : 4047 if (CONSTANT_P (x)) 4048 { 4049 output_addr_const (file, x); 4050 return; 4051 } 4052 break; 4053 case 'H' : 4054 case 'L' : 4055 if (GET_CODE (x) == REG) 4056 { 4057 /* L = least significant word, H = most significant word. */ 4058 if ((WORDS_BIG_ENDIAN != 0) ^ (code == 'L')) 4059 fputs (reg_names[REGNO (x)], file); 4060 else 4061 fputs (reg_names[REGNO (x)+1], file); 4062 } 4063 else if (GET_CODE (x) == CONST_INT 4064 || GET_CODE (x) == CONST_DOUBLE) 4065 { 4066 rtx first, second, word; 4067 4068 split_double (x, &first, &second); 4069 4070 if((WORDS_BIG_ENDIAN) == 0) 4071 word = (code == 'L' ? first : second); 4072 else 4073 word = (code == 'L' ? second : first); 4074 4075 fprintf (file, "0x%08" PRIx32, ((uint32_t) INTVAL (word))); 4076 } 4077 else 4078 output_operand_lossage ("invalid operand to %%H/%%L code"); 4079 return; 4080 case 'A' : 4081 { 4082 char str[30]; 4083 4084 gcc_assert (GET_CODE (x) == CONST_DOUBLE 4085 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT); 4086 4087 real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x), sizeof (str), 0, 1); 4088 fprintf (file, "%s", str); 4089 return; 4090 } 4091 case 'U' : 4092 /* Output a load/store with update indicator if appropriate. */ 4093 if (GET_CODE (x) == MEM) 4094 { 4095 rtx addr = XEXP (x, 0); 4096 switch (GET_CODE (addr)) 4097 { 4098 case PRE_INC: case PRE_DEC: case PRE_MODIFY: 4099 fputs (".a", file); break; 4100 case POST_INC: case POST_DEC: case POST_MODIFY: 4101 fputs (".ab", file); break; 4102 case PLUS: 4103 /* Are we using a scaled index? */ 4104 if (GET_CODE (XEXP (addr, 0)) == MULT) 4105 fputs (".as", file); 4106 /* Can we use a scaled offset? */ 4107 else if (CONST_INT_P (XEXP (addr, 1)) 4108 && GET_MODE_SIZE (GET_MODE (x)) > 1 4109 && (!(INTVAL (XEXP (addr, 1)) 4110 & (GET_MODE_SIZE (GET_MODE (x)) - 1) & 3)) 4111 /* Does it make a difference? */ 4112 && !SMALL_INT_RANGE(INTVAL (XEXP (addr, 1)), 4113 GET_MODE_SIZE (GET_MODE (x)) - 2, 0)) 4114 { 4115 fputs (".as", file); 4116 output_scaled = 1; 4117 } 4118 else if (LEGITIMATE_SMALL_DATA_ADDRESS_P (addr) 4119 && GET_MODE_SIZE (GET_MODE (x)) > 1) 4120 { 4121 tree decl = NULL_TREE; 4122 int align = 0; 4123 if (GET_CODE (XEXP (addr, 1)) == SYMBOL_REF) 4124 decl = SYMBOL_REF_DECL (XEXP (addr, 1)); 4125 else if (GET_CODE (XEXP (XEXP (XEXP (addr, 1), 0), 0)) 4126 == SYMBOL_REF) 4127 decl = SYMBOL_REF_DECL (XEXP (XEXP (XEXP (addr, 1), 0), 0)); 4128 if (decl) 4129 align = DECL_ALIGN (decl); 4130 align = align / BITS_PER_UNIT; 4131 if ((GET_MODE_SIZE (GET_MODE (x)) == 2) 4132 && align && ((align & 1) == 0)) 4133 fputs (".as", file); 4134 if ((GET_MODE_SIZE (GET_MODE (x)) >= 4) 4135 && align && ((align & 3) == 0)) 4136 fputs (".as", file); 4137 } 4138 break; 4139 case REG: 4140 break; 4141 default: 4142 gcc_assert (CONSTANT_P (addr)); break; 4143 } 4144 } 4145 else 4146 output_operand_lossage ("invalid operand to %%U code"); 4147 return; 4148 case 'V' : 4149 /* Output cache bypass indicator for a load/store insn. Volatile memory 4150 refs are defined to use the cache bypass mechanism. */ 4151 if (GET_CODE (x) == MEM) 4152 { 4153 if ((MEM_VOLATILE_P (x) && !TARGET_VOLATILE_CACHE_SET) 4154 || arc_is_uncached_mem_p (x)) 4155 fputs (".di", file); 4156 } 4157 else 4158 output_operand_lossage ("invalid operand to %%V code"); 4159 return; 4160 /* plt code. */ 4161 case 'P': 4162 case 0 : 4163 /* Do nothing special. */ 4164 break; 4165 case 'F': 4166 fputs (reg_names[REGNO (x)]+1, file); 4167 return; 4168 case '^': 4169 /* This punctuation character is needed because label references are 4170 printed in the output template using %l. This is a front end 4171 character, and when we want to emit a '@' before it, we have to use 4172 this '^'. */ 4173 4174 fputc('@',file); 4175 return; 4176 case 'O': 4177 /* Output an operator. */ 4178 switch (GET_CODE (x)) 4179 { 4180 case PLUS: fputs ("add", file); return; 4181 case SS_PLUS: fputs ("adds", file); return; 4182 case AND: fputs ("and", file); return; 4183 case IOR: fputs ("or", file); return; 4184 case XOR: fputs ("xor", file); return; 4185 case MINUS: fputs ("sub", file); return; 4186 case SS_MINUS: fputs ("subs", file); return; 4187 case ASHIFT: fputs ("asl", file); return; 4188 case ASHIFTRT: fputs ("asr", file); return; 4189 case LSHIFTRT: fputs ("lsr", file); return; 4190 case ROTATERT: fputs ("ror", file); return; 4191 case MULT: fputs ("mpy", file); return; 4192 case ABS: fputs ("abs", file); return; /* Unconditional. */ 4193 case NEG: fputs ("neg", file); return; 4194 case SS_NEG: fputs ("negs", file); return; 4195 case NOT: fputs ("not", file); return; /* Unconditional. */ 4196 case ZERO_EXTEND: 4197 fputs ("ext", file); /* bmsk allows predication. */ 4198 goto size_suffix; 4199 case SIGN_EXTEND: /* Unconditional. */ 4200 fputs ("sex", file); 4201 size_suffix: 4202 switch (GET_MODE (XEXP (x, 0))) 4203 { 4204 case E_QImode: fputs ("b", file); return; 4205 case E_HImode: fputs ("w", file); return; 4206 default: break; 4207 } 4208 break; 4209 case SS_TRUNCATE: 4210 if (GET_MODE (x) != HImode) 4211 break; 4212 fputs ("sat16", file); 4213 default: break; 4214 } 4215 output_operand_lossage ("invalid operand to %%O code"); return; 4216 case 'o': 4217 if (GET_CODE (x) == SYMBOL_REF) 4218 { 4219 assemble_name (file, XSTR (x, 0)); 4220 return; 4221 } 4222 break; 4223 case '&': 4224 if (TARGET_ANNOTATE_ALIGN) 4225 fprintf (file, "; unalign: %d", cfun->machine->unalign); 4226 return; 4227 case '+': 4228 if (TARGET_V2) 4229 fputs ("m", file); 4230 else 4231 fputs ("h", file); 4232 return; 4233 case '_': 4234 if (TARGET_V2) 4235 fputs ("h", file); 4236 else 4237 fputs ("w", file); 4238 return; 4239 default : 4240 /* Unknown flag. */ 4241 output_operand_lossage ("invalid operand output code"); 4242 } 4243 4244 switch (GET_CODE (x)) 4245 { 4246 case REG : 4247 fputs (reg_names[REGNO (x)], file); 4248 break; 4249 case MEM : 4250 { 4251 rtx addr = XEXP (x, 0); 4252 int size = GET_MODE_SIZE (GET_MODE (x)); 4253 4254 fputc ('[', file); 4255 4256 switch (GET_CODE (addr)) 4257 { 4258 case PRE_INC: case POST_INC: 4259 output_address (VOIDmode, 4260 plus_constant (Pmode, XEXP (addr, 0), size)); break; 4261 case PRE_DEC: case POST_DEC: 4262 output_address (VOIDmode, 4263 plus_constant (Pmode, XEXP (addr, 0), -size)); 4264 break; 4265 case PRE_MODIFY: case POST_MODIFY: 4266 output_address (VOIDmode, XEXP (addr, 1)); break; 4267 case PLUS: 4268 if (output_scaled) 4269 { 4270 output_address (VOIDmode, 4271 plus_constant (Pmode, XEXP (addr, 0), 4272 (INTVAL (XEXP (addr, 1)) 4273 >> (size == 2 ? 1 : 2)))); 4274 output_scaled = 0; 4275 } 4276 else 4277 output_address (VOIDmode, addr); 4278 break; 4279 default: 4280 if (flag_pic && CONSTANT_ADDRESS_P (addr)) 4281 arc_output_pic_addr_const (file, addr, code); 4282 else 4283 output_address (VOIDmode, addr); 4284 break; 4285 } 4286 fputc (']', file); 4287 break; 4288 } 4289 case CONST_DOUBLE : 4290 /* We handle SFmode constants here as output_addr_const doesn't. */ 4291 if (GET_MODE (x) == SFmode) 4292 { 4293 long l; 4294 4295 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l); 4296 fprintf (file, "0x%08lx", l); 4297 break; 4298 } 4299 /* FALLTHRU */ 4300 /* Let output_addr_const deal with it. */ 4301 default : 4302 if (flag_pic 4303 || (GET_CODE (x) == CONST 4304 && GET_CODE (XEXP (x, 0)) == UNSPEC 4305 && (XINT (XEXP (x, 0), 1) == UNSPEC_TLS_OFF 4306 || XINT (XEXP (x, 0), 1) == UNSPEC_TLS_GD)) 4307 || (GET_CODE (x) == CONST 4308 && GET_CODE (XEXP (x, 0)) == PLUS 4309 && GET_CODE (XEXP (XEXP (x, 0), 0)) == UNSPEC 4310 && (XINT (XEXP (XEXP (x, 0), 0), 1) == UNSPEC_TLS_OFF 4311 || XINT (XEXP (XEXP (x, 0), 0), 1) == UNSPEC_TLS_GD))) 4312 arc_output_pic_addr_const (file, x, code); 4313 else 4314 { 4315 /* FIXME: Dirty way to handle @var@sda+const. Shd be handled 4316 with asm_output_symbol_ref */ 4317 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS) 4318 { 4319 x = XEXP (x, 0); 4320 output_addr_const (file, XEXP (x, 0)); 4321 if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF && SYMBOL_REF_SMALL_P (XEXP (x, 0))) 4322 fprintf (file, "@sda"); 4323 4324 if (GET_CODE (XEXP (x, 1)) != CONST_INT 4325 || INTVAL (XEXP (x, 1)) >= 0) 4326 fprintf (file, "+"); 4327 output_addr_const (file, XEXP (x, 1)); 4328 } 4329 else 4330 output_addr_const (file, x); 4331 } 4332 if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_SMALL_P (x)) 4333 fprintf (file, "@sda"); 4334 break; 4335 } 4336 } 4337 4338 /* Print a memory address as an operand to reference that memory location. */ 4339 4340 void 4341 arc_print_operand_address (FILE *file , rtx addr) 4342 { 4343 register rtx base, index = 0; 4344 4345 switch (GET_CODE (addr)) 4346 { 4347 case REG : 4348 fputs (reg_names[REGNO (addr)], file); 4349 break; 4350 case SYMBOL_REF : 4351 output_addr_const (file, addr); 4352 if (SYMBOL_REF_SMALL_P (addr)) 4353 fprintf (file, "@sda"); 4354 break; 4355 case PLUS : 4356 if (GET_CODE (XEXP (addr, 0)) == MULT) 4357 index = XEXP (XEXP (addr, 0), 0), base = XEXP (addr, 1); 4358 else if (CONST_INT_P (XEXP (addr, 0))) 4359 index = XEXP (addr, 0), base = XEXP (addr, 1); 4360 else 4361 base = XEXP (addr, 0), index = XEXP (addr, 1); 4362 4363 gcc_assert (OBJECT_P (base)); 4364 arc_print_operand_address (file, base); 4365 if (CONSTANT_P (base) && CONST_INT_P (index)) 4366 fputc ('+', file); 4367 else 4368 fputc (',', file); 4369 gcc_assert (OBJECT_P (index)); 4370 arc_print_operand_address (file, index); 4371 break; 4372 case CONST: 4373 { 4374 rtx c = XEXP (addr, 0); 4375 4376 if ((GET_CODE (c) == UNSPEC 4377 && (XINT (c, 1) == UNSPEC_TLS_OFF 4378 || XINT (c, 1) == UNSPEC_TLS_IE)) 4379 || (GET_CODE (c) == PLUS 4380 && GET_CODE (XEXP (c, 0)) == UNSPEC 4381 && (XINT (XEXP (c, 0), 1) == UNSPEC_TLS_OFF 4382 || XINT (XEXP (c, 0), 1) == ARC_UNSPEC_GOTOFFPC))) 4383 { 4384 arc_output_pic_addr_const (file, c, 0); 4385 break; 4386 } 4387 gcc_assert (GET_CODE (c) == PLUS); 4388 gcc_assert (GET_CODE (XEXP (c, 0)) == SYMBOL_REF); 4389 gcc_assert (GET_CODE (XEXP (c, 1)) == CONST_INT); 4390 4391 output_address (VOIDmode, XEXP (addr, 0)); 4392 4393 break; 4394 } 4395 case PRE_INC : 4396 case PRE_DEC : 4397 /* We shouldn't get here as we've lost the mode of the memory object 4398 (which says how much to inc/dec by. */ 4399 gcc_unreachable (); 4400 break; 4401 default : 4402 if (flag_pic) 4403 arc_output_pic_addr_const (file, addr, 0); 4404 else 4405 output_addr_const (file, addr); 4406 break; 4407 } 4408 } 4409 4410 /* Conditional execution support. 4411 4412 This is based on the ARM port but for now is much simpler. 4413 4414 A finite state machine takes care of noticing whether or not instructions 4415 can be conditionally executed, and thus decrease execution time and code 4416 size by deleting branch instructions. The fsm is controlled by 4417 arc_ccfsm_advance (called by arc_final_prescan_insn), and controls the 4418 actions of PRINT_OPERAND. The patterns in the .md file for the branch 4419 insns also have a hand in this. */ 4420 /* The way we leave dealing with non-anulled or annull-false delay slot 4421 insns to the consumer is awkward. */ 4422 4423 /* The state of the fsm controlling condition codes are: 4424 0: normal, do nothing special 4425 1: don't output this insn 4426 2: don't output this insn 4427 3: make insns conditional 4428 4: make insns conditional 4429 5: make insn conditional (only for outputting anulled delay slot insns) 4430 4431 special value for cfun->machine->uid_ccfsm_state: 4432 6: return with but one insn before it since function start / call 4433 4434 State transitions (state->state by whom, under what condition): 4435 0 -> 1 arc_ccfsm_advance, if insn is a conditional branch skipping over 4436 some instructions. 4437 0 -> 2 arc_ccfsm_advance, if insn is a conditional branch followed 4438 by zero or more non-jump insns and an unconditional branch with 4439 the same target label as the condbranch. 4440 1 -> 3 branch patterns, after having not output the conditional branch 4441 2 -> 4 branch patterns, after having not output the conditional branch 4442 0 -> 5 branch patterns, for anulled delay slot insn. 4443 3 -> 0 ASM_OUTPUT_INTERNAL_LABEL, if the `target' label is reached 4444 (the target label has CODE_LABEL_NUMBER equal to 4445 arc_ccfsm_target_label). 4446 4 -> 0 arc_ccfsm_advance, if `target' unconditional branch is reached 4447 3 -> 1 arc_ccfsm_advance, finding an 'else' jump skipping over some insns. 4448 5 -> 0 when outputting the delay slot insn 4449 4450 If the jump clobbers the conditions then we use states 2 and 4. 4451 4452 A similar thing can be done with conditional return insns. 4453 4454 We also handle separating branches from sets of the condition code. 4455 This is done here because knowledge of the ccfsm state is required, 4456 we may not be outputting the branch. */ 4457 4458 /* arc_final_prescan_insn calls arc_ccfsm_advance to adjust arc_ccfsm_current, 4459 before letting final output INSN. */ 4460 4461 static void 4462 arc_ccfsm_advance (rtx_insn *insn, struct arc_ccfsm *state) 4463 { 4464 /* BODY will hold the body of INSN. */ 4465 register rtx body; 4466 4467 /* This will be 1 if trying to repeat the trick (ie: do the `else' part of 4468 an if/then/else), and things need to be reversed. */ 4469 int reverse = 0; 4470 4471 /* If we start with a return insn, we only succeed if we find another one. */ 4472 int seeking_return = 0; 4473 4474 /* START_INSN will hold the insn from where we start looking. This is the 4475 first insn after the following code_label if REVERSE is true. */ 4476 rtx_insn *start_insn = insn; 4477 4478 /* Type of the jump_insn. Brcc insns don't affect ccfsm changes, 4479 since they don't rely on a cmp preceding the. */ 4480 enum attr_type jump_insn_type; 4481 4482 /* Allow -mdebug-ccfsm to turn this off so we can see how well it does. 4483 We can't do this in macro FINAL_PRESCAN_INSN because its called from 4484 final_scan_insn which has `optimize' as a local. */ 4485 if (optimize < 2 || TARGET_NO_COND_EXEC) 4486 return; 4487 4488 /* Ignore notes and labels. */ 4489 if (!INSN_P (insn)) 4490 return; 4491 body = PATTERN (insn); 4492 /* If in state 4, check if the target branch is reached, in order to 4493 change back to state 0. */ 4494 if (state->state == 4) 4495 { 4496 if (insn == state->target_insn) 4497 { 4498 state->target_insn = NULL; 4499 state->state = 0; 4500 } 4501 return; 4502 } 4503 4504 /* If in state 3, it is possible to repeat the trick, if this insn is an 4505 unconditional branch to a label, and immediately following this branch 4506 is the previous target label which is only used once, and the label this 4507 branch jumps to is not too far off. Or in other words "we've done the 4508 `then' part, see if we can do the `else' part." */ 4509 if (state->state == 3) 4510 { 4511 if (simplejump_p (insn)) 4512 { 4513 start_insn = next_nonnote_insn (start_insn); 4514 if (GET_CODE (start_insn) == BARRIER) 4515 { 4516 /* ??? Isn't this always a barrier? */ 4517 start_insn = next_nonnote_insn (start_insn); 4518 } 4519 if (GET_CODE (start_insn) == CODE_LABEL 4520 && CODE_LABEL_NUMBER (start_insn) == state->target_label 4521 && LABEL_NUSES (start_insn) == 1) 4522 reverse = TRUE; 4523 else 4524 return; 4525 } 4526 else if (GET_CODE (body) == SIMPLE_RETURN) 4527 { 4528 start_insn = next_nonnote_insn (start_insn); 4529 if (GET_CODE (start_insn) == BARRIER) 4530 start_insn = next_nonnote_insn (start_insn); 4531 if (GET_CODE (start_insn) == CODE_LABEL 4532 && CODE_LABEL_NUMBER (start_insn) == state->target_label 4533 && LABEL_NUSES (start_insn) == 1) 4534 { 4535 reverse = TRUE; 4536 seeking_return = 1; 4537 } 4538 else 4539 return; 4540 } 4541 else 4542 return; 4543 } 4544 4545 if (GET_CODE (insn) != JUMP_INSN 4546 || GET_CODE (PATTERN (insn)) == ADDR_VEC 4547 || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC) 4548 return; 4549 4550 /* We can't predicate BRCC or loop ends. 4551 Also, when generating PIC code, and considering a medium range call, 4552 we can't predicate the call. */ 4553 jump_insn_type = get_attr_type (insn); 4554 if (jump_insn_type == TYPE_BRCC 4555 || jump_insn_type == TYPE_BRCC_NO_DELAY_SLOT 4556 || jump_insn_type == TYPE_LOOP_END 4557 || (jump_insn_type == TYPE_CALL && !get_attr_predicable (insn))) 4558 return; 4559 4560 /* This jump might be paralleled with a clobber of the condition codes, 4561 the jump should always come first. */ 4562 if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0) 4563 body = XVECEXP (body, 0, 0); 4564 4565 if (reverse 4566 || (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC 4567 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE)) 4568 { 4569 int insns_skipped = 0, fail = FALSE, succeed = FALSE; 4570 /* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */ 4571 int then_not_else = TRUE; 4572 /* Nonzero if next insn must be the target label. */ 4573 int next_must_be_target_label_p; 4574 rtx_insn *this_insn = start_insn; 4575 rtx label = 0; 4576 4577 /* Register the insn jumped to. */ 4578 if (reverse) 4579 { 4580 if (!seeking_return) 4581 label = XEXP (SET_SRC (body), 0); 4582 } 4583 else if (GET_CODE (XEXP (SET_SRC (body), 1)) == LABEL_REF) 4584 label = XEXP (XEXP (SET_SRC (body), 1), 0); 4585 else if (GET_CODE (XEXP (SET_SRC (body), 2)) == LABEL_REF) 4586 { 4587 label = XEXP (XEXP (SET_SRC (body), 2), 0); 4588 then_not_else = FALSE; 4589 } 4590 else if (GET_CODE (XEXP (SET_SRC (body), 1)) == SIMPLE_RETURN) 4591 seeking_return = 1; 4592 else if (GET_CODE (XEXP (SET_SRC (body), 2)) == SIMPLE_RETURN) 4593 { 4594 seeking_return = 1; 4595 then_not_else = FALSE; 4596 } 4597 else 4598 gcc_unreachable (); 4599 4600 /* If this is a non-annulled branch with a delay slot, there is 4601 no need to conditionalize the delay slot. */ 4602 if ((GET_CODE (PATTERN (NEXT_INSN (PREV_INSN (insn)))) == SEQUENCE) 4603 && state->state == 0 && !INSN_ANNULLED_BRANCH_P (insn)) 4604 { 4605 this_insn = NEXT_INSN (this_insn); 4606 } 4607 /* See how many insns this branch skips, and what kind of insns. If all 4608 insns are okay, and the label or unconditional branch to the same 4609 label is not too far away, succeed. */ 4610 for (insns_skipped = 0, next_must_be_target_label_p = FALSE; 4611 !fail && !succeed && insns_skipped < MAX_INSNS_SKIPPED; 4612 insns_skipped++) 4613 { 4614 rtx scanbody; 4615 4616 this_insn = next_nonnote_insn (this_insn); 4617 if (!this_insn) 4618 break; 4619 4620 if (next_must_be_target_label_p) 4621 { 4622 if (GET_CODE (this_insn) == BARRIER) 4623 continue; 4624 if (GET_CODE (this_insn) == CODE_LABEL 4625 && this_insn == label) 4626 { 4627 state->state = 1; 4628 succeed = TRUE; 4629 } 4630 else 4631 fail = TRUE; 4632 break; 4633 } 4634 4635 switch (GET_CODE (this_insn)) 4636 { 4637 case CODE_LABEL: 4638 /* Succeed if it is the target label, otherwise fail since 4639 control falls in from somewhere else. */ 4640 if (this_insn == label) 4641 { 4642 state->state = 1; 4643 succeed = TRUE; 4644 } 4645 else 4646 fail = TRUE; 4647 break; 4648 4649 case BARRIER: 4650 /* Succeed if the following insn is the target label. 4651 Otherwise fail. 4652 If return insns are used then the last insn in a function 4653 will be a barrier. */ 4654 next_must_be_target_label_p = TRUE; 4655 break; 4656 4657 case CALL_INSN: 4658 /* Can handle a call insn if there are no insns after it. 4659 IE: The next "insn" is the target label. We don't have to 4660 worry about delay slots as such insns are SEQUENCE's inside 4661 INSN's. ??? It is possible to handle such insns though. */ 4662 if (get_attr_cond (this_insn) == COND_CANUSE) 4663 next_must_be_target_label_p = TRUE; 4664 else 4665 fail = TRUE; 4666 break; 4667 4668 case JUMP_INSN: 4669 scanbody = PATTERN (this_insn); 4670 4671 /* If this is an unconditional branch to the same label, succeed. 4672 If it is to another label, do nothing. If it is conditional, 4673 fail. */ 4674 /* ??? Probably, the test for the SET and the PC are 4675 unnecessary. */ 4676 4677 if (GET_CODE (scanbody) == SET 4678 && GET_CODE (SET_DEST (scanbody)) == PC) 4679 { 4680 if (GET_CODE (SET_SRC (scanbody)) == LABEL_REF 4681 && XEXP (SET_SRC (scanbody), 0) == label && !reverse) 4682 { 4683 state->state = 2; 4684 succeed = TRUE; 4685 } 4686 else if (GET_CODE (SET_SRC (scanbody)) == IF_THEN_ELSE) 4687 fail = TRUE; 4688 else if (get_attr_cond (this_insn) != COND_CANUSE) 4689 fail = TRUE; 4690 } 4691 else if (GET_CODE (scanbody) == SIMPLE_RETURN 4692 && seeking_return) 4693 { 4694 state->state = 2; 4695 succeed = TRUE; 4696 } 4697 else if (GET_CODE (scanbody) == PARALLEL) 4698 { 4699 if (get_attr_cond (this_insn) != COND_CANUSE) 4700 fail = TRUE; 4701 } 4702 break; 4703 4704 case INSN: 4705 scanbody = PATTERN (this_insn); 4706 4707 /* We can only do this with insns that can use the condition 4708 codes (and don't set them). */ 4709 if (GET_CODE (scanbody) == SET 4710 || GET_CODE (scanbody) == PARALLEL) 4711 { 4712 if (get_attr_cond (this_insn) != COND_CANUSE) 4713 fail = TRUE; 4714 } 4715 /* We can't handle other insns like sequences. */ 4716 else 4717 fail = TRUE; 4718 break; 4719 4720 default: 4721 break; 4722 } 4723 } 4724 4725 if (succeed) 4726 { 4727 if ((!seeking_return) && (state->state == 1 || reverse)) 4728 state->target_label = CODE_LABEL_NUMBER (label); 4729 else if (seeking_return || state->state == 2) 4730 { 4731 while (this_insn && GET_CODE (PATTERN (this_insn)) == USE) 4732 { 4733 this_insn = next_nonnote_insn (this_insn); 4734 4735 gcc_assert (!this_insn || 4736 (GET_CODE (this_insn) != BARRIER 4737 && GET_CODE (this_insn) != CODE_LABEL)); 4738 } 4739 if (!this_insn) 4740 { 4741 /* Oh dear! we ran off the end, give up. */ 4742 extract_insn_cached (insn); 4743 state->state = 0; 4744 state->target_insn = NULL; 4745 return; 4746 } 4747 state->target_insn = this_insn; 4748 } 4749 else 4750 gcc_unreachable (); 4751 4752 /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from 4753 what it was. */ 4754 if (!reverse) 4755 { 4756 state->cond = XEXP (SET_SRC (body), 0); 4757 state->cc = get_arc_condition_code (XEXP (SET_SRC (body), 0)); 4758 } 4759 4760 if (reverse || then_not_else) 4761 state->cc = ARC_INVERSE_CONDITION_CODE (state->cc); 4762 } 4763 4764 /* Restore recog_operand. Getting the attributes of other insns can 4765 destroy this array, but final.c assumes that it remains intact 4766 across this call; since the insn has been recognized already we 4767 call insn_extract direct. */ 4768 extract_insn_cached (insn); 4769 } 4770 } 4771 4772 /* Record that we are currently outputting label NUM with prefix PREFIX. 4773 It it's the label we're looking for, reset the ccfsm machinery. 4774 4775 Called from ASM_OUTPUT_INTERNAL_LABEL. */ 4776 4777 static void 4778 arc_ccfsm_at_label (const char *prefix, int num, struct arc_ccfsm *state) 4779 { 4780 if (state->state == 3 && state->target_label == num 4781 && !strcmp (prefix, "L")) 4782 { 4783 state->state = 0; 4784 state->target_insn = NULL; 4785 } 4786 } 4787 4788 /* We are considering a conditional branch with the condition COND. 4789 Check if we want to conditionalize a delay slot insn, and if so modify 4790 the ccfsm state accordingly. 4791 REVERSE says branch will branch when the condition is false. */ 4792 void 4793 arc_ccfsm_record_condition (rtx cond, bool reverse, rtx_insn *jump, 4794 struct arc_ccfsm *state) 4795 { 4796 rtx_insn *seq_insn = NEXT_INSN (PREV_INSN (jump)); 4797 if (!state) 4798 state = &arc_ccfsm_current; 4799 4800 gcc_assert (state->state == 0); 4801 if (seq_insn != jump) 4802 { 4803 rtx insn = XVECEXP (PATTERN (seq_insn), 0, 1); 4804 4805 if (!as_a<rtx_insn *> (insn)->deleted () 4806 && INSN_ANNULLED_BRANCH_P (jump) 4807 && (TARGET_AT_DBR_CONDEXEC || INSN_FROM_TARGET_P (insn))) 4808 { 4809 state->cond = cond; 4810 state->cc = get_arc_condition_code (cond); 4811 if (!reverse) 4812 arc_ccfsm_current.cc 4813 = ARC_INVERSE_CONDITION_CODE (state->cc); 4814 rtx pat = PATTERN (insn); 4815 if (GET_CODE (pat) == COND_EXEC) 4816 gcc_assert ((INSN_FROM_TARGET_P (insn) 4817 ? ARC_INVERSE_CONDITION_CODE (state->cc) : state->cc) 4818 == get_arc_condition_code (XEXP (pat, 0))); 4819 else 4820 state->state = 5; 4821 } 4822 } 4823 } 4824 4825 /* Update *STATE as we would when we emit INSN. */ 4826 4827 static void 4828 arc_ccfsm_post_advance (rtx_insn *insn, struct arc_ccfsm *state) 4829 { 4830 enum attr_type type; 4831 4832 if (LABEL_P (insn)) 4833 arc_ccfsm_at_label ("L", CODE_LABEL_NUMBER (insn), state); 4834 else if (JUMP_P (insn) 4835 && GET_CODE (PATTERN (insn)) != ADDR_VEC 4836 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC 4837 && ((type = get_attr_type (insn)) == TYPE_BRANCH 4838 || ((type == TYPE_UNCOND_BRANCH 4839 || type == TYPE_RETURN) 4840 && ARC_CCFSM_BRANCH_DELETED_P (state)))) 4841 { 4842 if (ARC_CCFSM_BRANCH_DELETED_P (state)) 4843 ARC_CCFSM_RECORD_BRANCH_DELETED (state); 4844 else 4845 { 4846 rtx src = SET_SRC (PATTERN (insn)); 4847 arc_ccfsm_record_condition (XEXP (src, 0), XEXP (src, 1) == pc_rtx, 4848 insn, state); 4849 } 4850 } 4851 else if (arc_ccfsm_current.state == 5) 4852 arc_ccfsm_current.state = 0; 4853 } 4854 4855 /* Return true if the current insn, which is a conditional branch, is to be 4856 deleted. */ 4857 4858 bool 4859 arc_ccfsm_branch_deleted_p (void) 4860 { 4861 return ARC_CCFSM_BRANCH_DELETED_P (&arc_ccfsm_current); 4862 } 4863 4864 /* Record a branch isn't output because subsequent insns can be 4865 conditionalized. */ 4866 4867 void 4868 arc_ccfsm_record_branch_deleted (void) 4869 { 4870 ARC_CCFSM_RECORD_BRANCH_DELETED (&arc_ccfsm_current); 4871 } 4872 4873 /* During insn output, indicate if the current insn is predicated. */ 4874 4875 bool 4876 arc_ccfsm_cond_exec_p (void) 4877 { 4878 return (cfun->machine->prescan_initialized 4879 && ARC_CCFSM_COND_EXEC_P (&arc_ccfsm_current)); 4880 } 4881 4882 /* When deciding if an insn should be output short, we want to know something 4883 about the following insns: 4884 - if another insn follows which we know we can output as a short insn 4885 before an alignment-sensitive point, we can output this insn short: 4886 the decision about the eventual alignment can be postponed. 4887 - if a to-be-aligned label comes next, we should output this insn such 4888 as to get / preserve 4-byte alignment. 4889 - if a likely branch without delay slot insn, or a call with an immediately 4890 following short insn comes next, we should out output this insn such as to 4891 get / preserve 2 mod 4 unalignment. 4892 - do the same for a not completely unlikely branch with a short insn 4893 following before any other branch / label. 4894 - in order to decide if we are actually looking at a branch, we need to 4895 call arc_ccfsm_advance. 4896 - in order to decide if we are looking at a short insn, we should know 4897 if it is conditionalized. To a first order of approximation this is 4898 the case if the state from arc_ccfsm_advance from before this insn 4899 indicates the insn is conditionalized. However, a further refinement 4900 could be to not conditionalize an insn if the destination register(s) 4901 is/are dead in the non-executed case. */ 4902 /* Return non-zero if INSN should be output as a short insn. UNALIGN is 4903 zero if the current insn is aligned to a 4-byte-boundary, two otherwise. 4904 If CHECK_ATTR is greater than 0, check the iscompact attribute first. */ 4905 4906 static int 4907 arc_verify_short (rtx_insn *insn, int, int check_attr) 4908 { 4909 enum attr_iscompact iscompact; 4910 4911 if (check_attr > 0) 4912 { 4913 iscompact = get_attr_iscompact (insn); 4914 if (iscompact == ISCOMPACT_FALSE) 4915 return 0; 4916 } 4917 4918 return (get_attr_length (insn) & 2) != 0; 4919 } 4920 4921 /* When outputting an instruction (alternative) that can potentially be short, 4922 output the short suffix if the insn is in fact short, and update 4923 cfun->machine->unalign accordingly. */ 4924 4925 static void 4926 output_short_suffix (FILE *file) 4927 { 4928 rtx_insn *insn = current_output_insn; 4929 4930 if (arc_verify_short (insn, cfun->machine->unalign, 1)) 4931 { 4932 fprintf (file, "_s"); 4933 cfun->machine->unalign ^= 2; 4934 } 4935 /* Restore recog_operand. */ 4936 extract_insn_cached (insn); 4937 } 4938 4939 /* Implement FINAL_PRESCAN_INSN. */ 4940 4941 void 4942 arc_final_prescan_insn (rtx_insn *insn, rtx *opvec ATTRIBUTE_UNUSED, 4943 int noperands ATTRIBUTE_UNUSED) 4944 { 4945 if (TARGET_DUMPISIZE) 4946 fprintf (asm_out_file, "\n; at %04x\n", INSN_ADDRESSES (INSN_UID (insn))); 4947 4948 if (!cfun->machine->prescan_initialized) 4949 { 4950 /* Clear lingering state from branch shortening. */ 4951 memset (&arc_ccfsm_current, 0, sizeof arc_ccfsm_current); 4952 cfun->machine->prescan_initialized = 1; 4953 } 4954 arc_ccfsm_advance (insn, &arc_ccfsm_current); 4955 } 4956 4957 /* Given FROM and TO register numbers, say whether this elimination is allowed. 4958 Frame pointer elimination is automatically handled. 4959 4960 All eliminations are permissible. If we need a frame 4961 pointer, we must eliminate ARG_POINTER_REGNUM into 4962 FRAME_POINTER_REGNUM and not into STACK_POINTER_REGNUM. */ 4963 4964 static bool 4965 arc_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to) 4966 { 4967 return ((to == FRAME_POINTER_REGNUM) || !arc_frame_pointer_needed ()); 4968 } 4969 4970 /* Define the offset between two registers, one to be eliminated, and 4971 the other its replacement, at the start of a routine. */ 4972 4973 int 4974 arc_initial_elimination_offset (int from, int to) 4975 { 4976 if (!cfun->machine->frame_info.initialized) 4977 arc_compute_frame_size (); 4978 4979 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM) 4980 { 4981 return (cfun->machine->frame_info.extra_size 4982 + cfun->machine->frame_info.reg_size); 4983 } 4984 4985 if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM) 4986 { 4987 return (cfun->machine->frame_info.total_size 4988 - cfun->machine->frame_info.pretend_size); 4989 } 4990 4991 if ((from == FRAME_POINTER_REGNUM) && (to == STACK_POINTER_REGNUM)) 4992 { 4993 return (cfun->machine->frame_info.total_size 4994 - (cfun->machine->frame_info.pretend_size 4995 + cfun->machine->frame_info.extra_size 4996 + cfun->machine->frame_info.reg_size)); 4997 } 4998 4999 gcc_unreachable (); 5000 } 5001 5002 static bool 5003 arc_frame_pointer_required (void) 5004 { 5005 return cfun->calls_alloca || crtl->calls_eh_return; 5006 } 5007 5008 5009 /* Return the destination address of a branch. */ 5010 5011 static int 5012 branch_dest (rtx branch) 5013 { 5014 rtx pat = PATTERN (branch); 5015 rtx dest = (GET_CODE (pat) == PARALLEL 5016 ? SET_SRC (XVECEXP (pat, 0, 0)) : SET_SRC (pat)); 5017 int dest_uid; 5018 5019 if (GET_CODE (dest) == IF_THEN_ELSE) 5020 dest = XEXP (dest, XEXP (dest, 1) == pc_rtx ? 2 : 1); 5021 5022 dest = XEXP (dest, 0); 5023 dest_uid = INSN_UID (dest); 5024 5025 return INSN_ADDRESSES (dest_uid); 5026 } 5027 5028 5029 /* Implement TARGET_ENCODE_SECTION_INFO hook. */ 5030 5031 static void 5032 arc_encode_section_info (tree decl, rtx rtl, int first) 5033 { 5034 /* For sdata, SYMBOL_FLAG_LOCAL and SYMBOL_FLAG_FUNCTION. 5035 This clears machine specific flags, so has to come first. */ 5036 default_encode_section_info (decl, rtl, first); 5037 5038 /* Check if it is a function, and whether it has the 5039 [long/medium/short]_call attribute specified. */ 5040 if (TREE_CODE (decl) == FUNCTION_DECL) 5041 { 5042 rtx symbol = XEXP (rtl, 0); 5043 int flags = SYMBOL_REF_FLAGS (symbol); 5044 5045 tree attr = (TREE_TYPE (decl) != error_mark_node 5046 ? TYPE_ATTRIBUTES (TREE_TYPE (decl)) : NULL_TREE); 5047 tree long_call_attr = lookup_attribute ("long_call", attr); 5048 tree medium_call_attr = lookup_attribute ("medium_call", attr); 5049 tree short_call_attr = lookup_attribute ("short_call", attr); 5050 5051 if (long_call_attr != NULL_TREE) 5052 flags |= SYMBOL_FLAG_LONG_CALL; 5053 else if (medium_call_attr != NULL_TREE) 5054 flags |= SYMBOL_FLAG_MEDIUM_CALL; 5055 else if (short_call_attr != NULL_TREE) 5056 flags |= SYMBOL_FLAG_SHORT_CALL; 5057 5058 SYMBOL_REF_FLAGS (symbol) = flags; 5059 } 5060 else if (TREE_CODE (decl) == VAR_DECL) 5061 { 5062 rtx symbol = XEXP (rtl, 0); 5063 5064 tree attr = (TREE_TYPE (decl) != error_mark_node 5065 ? DECL_ATTRIBUTES (decl) : NULL_TREE); 5066 5067 tree sec_attr = lookup_attribute ("section", attr); 5068 if (sec_attr) 5069 { 5070 const char *sec_name 5071 = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (sec_attr))); 5072 if (strcmp (sec_name, ".cmem") == 0 5073 || strcmp (sec_name, ".cmem_shared") == 0 5074 || strcmp (sec_name, ".cmem_private") == 0) 5075 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_CMEM; 5076 } 5077 } 5078 } 5079 5080 /* This is how to output a definition of an internal numbered label where 5081 PREFIX is the class of label and NUM is the number within the class. */ 5082 5083 static void arc_internal_label (FILE *stream, const char *prefix, unsigned long labelno) 5084 { 5085 if (cfun) 5086 arc_ccfsm_at_label (prefix, labelno, &arc_ccfsm_current); 5087 default_internal_label (stream, prefix, labelno); 5088 } 5089 5090 /* Set the cpu type and print out other fancy things, 5091 at the top of the file. */ 5092 5093 static void arc_file_start (void) 5094 { 5095 default_file_start (); 5096 fprintf (asm_out_file, "\t.cpu %s\n", arc_cpu_string); 5097 5098 /* Set some want to have build attributes. */ 5099 asm_fprintf (asm_out_file, "\t.arc_attribute Tag_ARC_PCS_config, %d\n", 5100 ATTRIBUTE_PCS); 5101 asm_fprintf (asm_out_file, "\t.arc_attribute Tag_ARC_ABI_rf16, %d\n", 5102 TARGET_RF16 ? 1 : 0); 5103 asm_fprintf (asm_out_file, "\t.arc_attribute Tag_ARC_ABI_pic, %d\n", 5104 flag_pic ? 2 : 0); 5105 asm_fprintf (asm_out_file, "\t.arc_attribute Tag_ARC_ABI_tls, %d\n", 5106 (arc_tp_regno != -1) ? 1 : 0); 5107 asm_fprintf (asm_out_file, "\t.arc_attribute Tag_ARC_ABI_sda, %d\n", 5108 TARGET_NO_SDATA_SET ? 0 : 2); 5109 asm_fprintf (asm_out_file, "\t.arc_attribute Tag_ARC_ABI_exceptions, %d\n", 5110 TARGET_OPTFPE ? 1 : 0); 5111 if (TARGET_V2) 5112 asm_fprintf (asm_out_file, "\t.arc_attribute Tag_ARC_CPU_variation, %d\n", 5113 arc_tune == ARC_TUNE_CORE_3 ? 3 : 2); 5114 } 5115 5116 /* Implement `TARGET_ASM_FILE_END'. */ 5117 /* Outputs to the stdio stream FILE jli related text. */ 5118 5119 void arc_file_end (void) 5120 { 5121 arc_jli_section *sec = arc_jli_sections; 5122 5123 while (sec != NULL) 5124 { 5125 fprintf (asm_out_file, "\n"); 5126 fprintf (asm_out_file, "# JLI entry for function "); 5127 assemble_name (asm_out_file, sec->name); 5128 fprintf (asm_out_file, "\n\t.section .jlitab, \"axG\", @progbits, " 5129 ".jlitab."); 5130 assemble_name (asm_out_file, sec->name); 5131 fprintf (asm_out_file,", comdat\n"); 5132 5133 fprintf (asm_out_file, "\t.align\t4\n"); 5134 fprintf (asm_out_file, "__jli."); 5135 assemble_name (asm_out_file, sec->name); 5136 fprintf (asm_out_file, ":\n\t.weak __jli."); 5137 assemble_name (asm_out_file, sec->name); 5138 fprintf (asm_out_file, "\n\tb\t@"); 5139 assemble_name (asm_out_file, sec->name); 5140 fprintf (asm_out_file, "\n"); 5141 sec = sec->next; 5142 } 5143 file_end_indicate_exec_stack (); 5144 } 5145 5146 /* Cost functions. */ 5147 5148 /* Compute a (partial) cost for rtx X. Return true if the complete 5149 cost has been computed, and false if subexpressions should be 5150 scanned. In either case, *TOTAL contains the cost result. */ 5151 5152 static bool 5153 arc_rtx_costs (rtx x, machine_mode mode, int outer_code, 5154 int opno ATTRIBUTE_UNUSED, int *total, bool speed) 5155 { 5156 int code = GET_CODE (x); 5157 5158 switch (code) 5159 { 5160 /* Small integers are as cheap as registers. */ 5161 case CONST_INT: 5162 { 5163 bool nolimm = false; /* Can we do without long immediate? */ 5164 bool fast = false; /* Is the result available immediately? */ 5165 bool condexec = false; /* Does this allow conditiobnal execution? */ 5166 bool compact = false; /* Is a 16 bit opcode available? */ 5167 /* CONDEXEC also implies that we can have an unconditional 5168 3-address operation. */ 5169 5170 nolimm = compact = condexec = false; 5171 if (UNSIGNED_INT6 (INTVAL (x))) 5172 nolimm = condexec = compact = true; 5173 else 5174 { 5175 if (SMALL_INT (INTVAL (x))) 5176 nolimm = fast = true; 5177 switch (outer_code) 5178 { 5179 case AND: /* bclr, bmsk, ext[bw] */ 5180 if (satisfies_constraint_Ccp (x) /* bclr */ 5181 || satisfies_constraint_C1p (x) /* bmsk */) 5182 nolimm = fast = condexec = compact = true; 5183 break; 5184 case IOR: /* bset */ 5185 if (satisfies_constraint_C0p (x)) /* bset */ 5186 nolimm = fast = condexec = compact = true; 5187 break; 5188 case XOR: 5189 if (satisfies_constraint_C0p (x)) /* bxor */ 5190 nolimm = fast = condexec = true; 5191 break; 5192 case SET: 5193 if (satisfies_constraint_Crr (x)) /* ror b,u6 */ 5194 nolimm = true; 5195 default: 5196 break; 5197 } 5198 } 5199 /* FIXME: Add target options to attach a small cost if 5200 condexec / compact is not true. */ 5201 if (nolimm) 5202 { 5203 *total = 0; 5204 return true; 5205 } 5206 } 5207 /* FALLTHRU */ 5208 5209 /* 4 byte values can be fetched as immediate constants - 5210 let's give that the cost of an extra insn. */ 5211 case CONST: 5212 case LABEL_REF: 5213 case SYMBOL_REF: 5214 *total = COSTS_N_INSNS (1); 5215 return true; 5216 5217 case CONST_DOUBLE: 5218 { 5219 rtx first, second; 5220 5221 if (TARGET_DPFP) 5222 { 5223 *total = COSTS_N_INSNS (1); 5224 return true; 5225 } 5226 split_double (x, &first, &second); 5227 *total = COSTS_N_INSNS (!SMALL_INT (INTVAL (first)) 5228 + !SMALL_INT (INTVAL (second))); 5229 return true; 5230 } 5231 5232 /* Encourage synth_mult to find a synthetic multiply when reasonable. 5233 If we need more than 12 insns to do a multiply, then go out-of-line, 5234 since the call overhead will be < 10% of the cost of the multiply. */ 5235 case ASHIFT: 5236 case ASHIFTRT: 5237 case LSHIFTRT: 5238 if (TARGET_BARREL_SHIFTER) 5239 { 5240 /* If we want to shift a constant, we need a LIMM. */ 5241 /* ??? when the optimizers want to know if a constant should be 5242 hoisted, they ask for the cost of the constant. OUTER_CODE is 5243 insufficient context for shifts since we don't know which operand 5244 we are looking at. */ 5245 if (CONSTANT_P (XEXP (x, 0))) 5246 { 5247 *total += (COSTS_N_INSNS (2) 5248 + rtx_cost (XEXP (x, 1), mode, (enum rtx_code) code, 5249 0, speed)); 5250 return true; 5251 } 5252 *total = COSTS_N_INSNS (1); 5253 } 5254 else if (GET_CODE (XEXP (x, 1)) != CONST_INT) 5255 *total = COSTS_N_INSNS (16); 5256 else 5257 { 5258 *total = COSTS_N_INSNS (INTVAL (XEXP ((x), 1))); 5259 /* ??? want_to_gcse_p can throw negative shift counts at us, 5260 and then panics when it gets a negative cost as result. 5261 Seen for gcc.c-torture/compile/20020710-1.c -Os . */ 5262 if (*total < 0) 5263 *total = 0; 5264 } 5265 return false; 5266 5267 case DIV: 5268 case UDIV: 5269 if (speed) 5270 *total = COSTS_N_INSNS(30); 5271 else 5272 *total = COSTS_N_INSNS(1); 5273 return false; 5274 5275 case MULT: 5276 if ((TARGET_DPFP && GET_MODE (x) == DFmode)) 5277 *total = COSTS_N_INSNS (1); 5278 else if (speed) 5279 *total= arc_multcost; 5280 /* We do not want synth_mult sequences when optimizing 5281 for size. */ 5282 else if (TARGET_MUL64_SET || TARGET_ARC700_MPY) 5283 *total = COSTS_N_INSNS (1); 5284 else 5285 *total = COSTS_N_INSNS (2); 5286 return false; 5287 case PLUS: 5288 if ((GET_CODE (XEXP (x, 0)) == ASHIFT 5289 && _1_2_3_operand (XEXP (XEXP (x, 0), 1), VOIDmode)) 5290 || (GET_CODE (XEXP (x, 0)) == MULT 5291 && _2_4_8_operand (XEXP (XEXP (x, 0), 1), VOIDmode))) 5292 { 5293 *total += (rtx_cost (XEXP (x, 1), mode, PLUS, 0, speed) 5294 + rtx_cost (XEXP (XEXP (x, 0), 0), mode, PLUS, 1, speed)); 5295 return true; 5296 } 5297 return false; 5298 case MINUS: 5299 if ((GET_CODE (XEXP (x, 1)) == ASHIFT 5300 && _1_2_3_operand (XEXP (XEXP (x, 1), 1), VOIDmode)) 5301 || (GET_CODE (XEXP (x, 1)) == MULT 5302 && _2_4_8_operand (XEXP (XEXP (x, 1), 1), VOIDmode))) 5303 { 5304 *total += (rtx_cost (XEXP (x, 0), mode, PLUS, 0, speed) 5305 + rtx_cost (XEXP (XEXP (x, 1), 0), mode, PLUS, 1, speed)); 5306 return true; 5307 } 5308 return false; 5309 case COMPARE: 5310 { 5311 rtx op0 = XEXP (x, 0); 5312 rtx op1 = XEXP (x, 1); 5313 5314 if (GET_CODE (op0) == ZERO_EXTRACT && op1 == const0_rtx 5315 && XEXP (op0, 1) == const1_rtx) 5316 { 5317 /* btst / bbit0 / bbit1: 5318 Small integers and registers are free; everything else can 5319 be put in a register. */ 5320 mode = GET_MODE (XEXP (op0, 0)); 5321 *total = (rtx_cost (XEXP (op0, 0), mode, SET, 1, speed) 5322 + rtx_cost (XEXP (op0, 2), mode, SET, 1, speed)); 5323 return true; 5324 } 5325 if (GET_CODE (op0) == AND && op1 == const0_rtx 5326 && satisfies_constraint_C1p (XEXP (op0, 1))) 5327 { 5328 /* bmsk.f */ 5329 *total = rtx_cost (XEXP (op0, 0), VOIDmode, SET, 1, speed); 5330 return true; 5331 } 5332 /* add.f */ 5333 if (GET_CODE (op1) == NEG) 5334 { 5335 /* op0 might be constant, the inside of op1 is rather 5336 unlikely to be so. So swapping the operands might lower 5337 the cost. */ 5338 mode = GET_MODE (op0); 5339 *total = (rtx_cost (op0, mode, PLUS, 1, speed) 5340 + rtx_cost (XEXP (op1, 0), mode, PLUS, 0, speed)); 5341 } 5342 return false; 5343 } 5344 case EQ: case NE: 5345 if (outer_code == IF_THEN_ELSE 5346 && GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT 5347 && XEXP (x, 1) == const0_rtx 5348 && XEXP (XEXP (x, 0), 1) == const1_rtx) 5349 { 5350 /* btst / bbit0 / bbit1: 5351 Small integers and registers are free; everything else can 5352 be put in a register. */ 5353 rtx op0 = XEXP (x, 0); 5354 5355 mode = GET_MODE (XEXP (op0, 0)); 5356 *total = (rtx_cost (XEXP (op0, 0), mode, SET, 1, speed) 5357 + rtx_cost (XEXP (op0, 2), mode, SET, 1, speed)); 5358 return true; 5359 } 5360 /* Fall through. */ 5361 /* scc_insn expands into two insns. */ 5362 case GTU: case GEU: case LEU: 5363 if (mode == SImode) 5364 *total += COSTS_N_INSNS (1); 5365 return false; 5366 case LTU: /* might use adc. */ 5367 if (mode == SImode) 5368 *total += COSTS_N_INSNS (1) - 1; 5369 return false; 5370 default: 5371 return false; 5372 } 5373 } 5374 5375 /* Return true if ADDR is a valid pic address. 5376 A valid pic address on arc should look like 5377 const (unspec (SYMBOL_REF/LABEL) (ARC_UNSPEC_GOTOFF/ARC_UNSPEC_GOT)) */ 5378 5379 bool 5380 arc_legitimate_pic_addr_p (rtx addr) 5381 { 5382 if (GET_CODE (addr) != CONST) 5383 return false; 5384 5385 addr = XEXP (addr, 0); 5386 5387 5388 if (GET_CODE (addr) == PLUS) 5389 { 5390 if (GET_CODE (XEXP (addr, 1)) != CONST_INT) 5391 return false; 5392 addr = XEXP (addr, 0); 5393 } 5394 5395 if (GET_CODE (addr) != UNSPEC 5396 || XVECLEN (addr, 0) != 1) 5397 return false; 5398 5399 /* Must be one of @GOT, @GOTOFF, @GOTOFFPC, @tlsgd, tlsie. */ 5400 if (XINT (addr, 1) != ARC_UNSPEC_GOT 5401 && XINT (addr, 1) != ARC_UNSPEC_GOTOFF 5402 && XINT (addr, 1) != ARC_UNSPEC_GOTOFFPC 5403 && XINT (addr, 1) != UNSPEC_TLS_GD 5404 && XINT (addr, 1) != UNSPEC_TLS_IE) 5405 return false; 5406 5407 if (GET_CODE (XVECEXP (addr, 0, 0)) != SYMBOL_REF 5408 && GET_CODE (XVECEXP (addr, 0, 0)) != LABEL_REF) 5409 return false; 5410 5411 return true; 5412 } 5413 5414 5415 5416 /* Return true if OP contains a symbol reference. */ 5417 5418 static bool 5419 symbolic_reference_mentioned_p (rtx op) 5420 { 5421 register const char *fmt; 5422 register int i; 5423 5424 if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF) 5425 return true; 5426 5427 fmt = GET_RTX_FORMAT (GET_CODE (op)); 5428 for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--) 5429 { 5430 if (fmt[i] == 'E') 5431 { 5432 register int j; 5433 5434 for (j = XVECLEN (op, i) - 1; j >= 0; j--) 5435 if (symbolic_reference_mentioned_p (XVECEXP (op, i, j))) 5436 return true; 5437 } 5438 5439 else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i))) 5440 return true; 5441 } 5442 5443 return false; 5444 } 5445 5446 /* Return true if OP contains a SYMBOL_REF that is not wrapped in an unspec. 5447 If SKIP_LOCAL is true, skip symbols that bind locally. 5448 This is used further down in this file, and, without SKIP_LOCAL, 5449 in the addsi3 / subsi3 expanders when generating PIC code. */ 5450 5451 bool 5452 arc_raw_symbolic_reference_mentioned_p (rtx op, bool skip_local) 5453 { 5454 register const char *fmt; 5455 register int i; 5456 5457 if (GET_CODE(op) == UNSPEC) 5458 return false; 5459 5460 if (GET_CODE (op) == SYMBOL_REF) 5461 { 5462 if (SYMBOL_REF_TLS_MODEL (op)) 5463 return true; 5464 if (!flag_pic) 5465 return false; 5466 tree decl = SYMBOL_REF_DECL (op); 5467 return !skip_local || !decl || !default_binds_local_p (decl); 5468 } 5469 5470 fmt = GET_RTX_FORMAT (GET_CODE (op)); 5471 for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--) 5472 { 5473 if (fmt[i] == 'E') 5474 { 5475 register int j; 5476 5477 for (j = XVECLEN (op, i) - 1; j >= 0; j--) 5478 if (arc_raw_symbolic_reference_mentioned_p (XVECEXP (op, i, j), 5479 skip_local)) 5480 return true; 5481 } 5482 5483 else if (fmt[i] == 'e' 5484 && arc_raw_symbolic_reference_mentioned_p (XEXP (op, i), 5485 skip_local)) 5486 return true; 5487 } 5488 5489 return false; 5490 } 5491 5492 /* Get the thread pointer. */ 5493 5494 static rtx 5495 arc_get_tp (void) 5496 { 5497 /* If arc_tp_regno has been set, we can use that hard register 5498 directly as a base register. */ 5499 if (arc_tp_regno != -1) 5500 return gen_rtx_REG (Pmode, arc_tp_regno); 5501 5502 /* Otherwise, call __read_tp. Copy the result to a pseudo to avoid 5503 conflicts with function arguments / results. */ 5504 rtx reg = gen_reg_rtx (Pmode); 5505 emit_insn (gen_tls_load_tp_soft ()); 5506 emit_move_insn (reg, gen_rtx_REG (Pmode, R0_REG)); 5507 return reg; 5508 } 5509 5510 /* Helper to be used by TLS Global dynamic model. */ 5511 5512 static rtx 5513 arc_emit_call_tls_get_addr (rtx sym, int reloc, rtx eqv) 5514 { 5515 rtx r0 = gen_rtx_REG (Pmode, R0_REG); 5516 rtx call_fusage = NULL_RTX; 5517 5518 start_sequence (); 5519 5520 rtx x = arc_unspec_offset (sym, reloc); 5521 emit_move_insn (r0, x); 5522 use_reg (&call_fusage, r0); 5523 5524 gcc_assert (reloc == UNSPEC_TLS_GD); 5525 rtx call_insn = emit_call_insn (gen_tls_gd_get_addr (sym)); 5526 /* Should we set RTL_CONST_CALL_P? We read memory, but not in a 5527 way that the application should care. */ 5528 RTL_PURE_CALL_P (call_insn) = 1; 5529 add_function_usage_to (call_insn, call_fusage); 5530 5531 rtx_insn *insns = get_insns (); 5532 end_sequence (); 5533 5534 rtx dest = gen_reg_rtx (Pmode); 5535 emit_libcall_block (insns, dest, r0, eqv); 5536 return dest; 5537 } 5538 5539 #define DTPOFF_ZERO_SYM ".tdata" 5540 5541 /* Return a legitimized address for ADDR, 5542 which is a SYMBOL_REF with tls_model MODEL. */ 5543 5544 static rtx 5545 arc_legitimize_tls_address (rtx addr, enum tls_model model) 5546 { 5547 if (!flag_pic && model == TLS_MODEL_LOCAL_DYNAMIC) 5548 model = TLS_MODEL_LOCAL_EXEC; 5549 5550 switch (model) 5551 { 5552 case TLS_MODEL_LOCAL_DYNAMIC: 5553 rtx base; 5554 tree decl; 5555 const char *base_name; 5556 rtvec v; 5557 5558 decl = SYMBOL_REF_DECL (addr); 5559 base_name = DTPOFF_ZERO_SYM; 5560 if (decl && bss_initializer_p (decl)) 5561 base_name = ".tbss"; 5562 5563 base = gen_rtx_SYMBOL_REF (Pmode, base_name); 5564 if (strcmp (base_name, DTPOFF_ZERO_SYM) == 0) 5565 { 5566 if (!flag_pic) 5567 goto local_exec; 5568 v = gen_rtvec (1, addr); 5569 } 5570 else 5571 v = gen_rtvec (2, addr, base); 5572 addr = gen_rtx_UNSPEC (Pmode, v, UNSPEC_TLS_OFF); 5573 addr = gen_rtx_CONST (Pmode, addr); 5574 base = arc_legitimize_tls_address (base, TLS_MODEL_GLOBAL_DYNAMIC); 5575 return gen_rtx_PLUS (Pmode, force_reg (Pmode, base), addr); 5576 5577 case TLS_MODEL_GLOBAL_DYNAMIC: 5578 return arc_emit_call_tls_get_addr (addr, UNSPEC_TLS_GD, addr); 5579 5580 case TLS_MODEL_INITIAL_EXEC: 5581 addr = arc_unspec_offset (addr, UNSPEC_TLS_IE); 5582 addr = copy_to_mode_reg (Pmode, gen_const_mem (Pmode, addr)); 5583 return gen_rtx_PLUS (Pmode, arc_get_tp (), addr); 5584 5585 case TLS_MODEL_LOCAL_EXEC: 5586 local_exec: 5587 addr = arc_unspec_offset (addr, UNSPEC_TLS_OFF); 5588 return gen_rtx_PLUS (Pmode, arc_get_tp (), addr); 5589 default: 5590 gcc_unreachable (); 5591 } 5592 } 5593 5594 /* Legitimize a pic address reference in ORIG. 5595 The return value is the legitimated address. 5596 If OLDX is non-zero, it is the target to assign the address to first. */ 5597 5598 static rtx 5599 arc_legitimize_pic_address (rtx orig, rtx oldx) 5600 { 5601 rtx addr = orig; 5602 rtx pat = orig; 5603 rtx base; 5604 5605 if (oldx == orig) 5606 oldx = NULL; 5607 5608 if (GET_CODE (addr) == LABEL_REF) 5609 ; /* Do nothing. */ 5610 else if (GET_CODE (addr) == SYMBOL_REF) 5611 { 5612 enum tls_model model = SYMBOL_REF_TLS_MODEL (addr); 5613 if (model != 0) 5614 return arc_legitimize_tls_address (addr, model); 5615 else if (!flag_pic) 5616 return orig; 5617 else if (CONSTANT_POOL_ADDRESS_P (addr) || SYMBOL_REF_LOCAL_P (addr)) 5618 return arc_unspec_offset (addr, ARC_UNSPEC_GOTOFFPC); 5619 5620 /* This symbol must be referenced via a load from the Global 5621 Offset Table (@GOTPC). */ 5622 pat = arc_unspec_offset (addr, ARC_UNSPEC_GOT); 5623 pat = gen_const_mem (Pmode, pat); 5624 5625 if (oldx == NULL) 5626 oldx = gen_reg_rtx (Pmode); 5627 5628 emit_move_insn (oldx, pat); 5629 pat = oldx; 5630 } 5631 else 5632 { 5633 if (GET_CODE (addr) == CONST) 5634 { 5635 addr = XEXP (addr, 0); 5636 if (GET_CODE (addr) == UNSPEC) 5637 { 5638 /* Check that the unspec is one of the ones we generate? */ 5639 return orig; 5640 } 5641 /* fwprop is placing in the REG_EQUIV notes constant pic 5642 unspecs expressions. Then, loop may use these notes for 5643 optimizations resulting in complex patterns that are not 5644 supported by the current implementation. The following 5645 two if-cases are simplifying the complex patters to 5646 simpler ones. */ 5647 else if (GET_CODE (addr) == MINUS) 5648 { 5649 rtx op0 = XEXP (addr, 0); 5650 rtx op1 = XEXP (addr, 1); 5651 gcc_assert (oldx); 5652 gcc_assert (GET_CODE (op1) == UNSPEC); 5653 5654 emit_move_insn (oldx, 5655 gen_rtx_CONST (SImode, 5656 arc_legitimize_pic_address (op1, 5657 NULL_RTX))); 5658 emit_insn (gen_rtx_SET (oldx, gen_rtx_MINUS (SImode, op0, oldx))); 5659 return oldx; 5660 5661 } 5662 else if (GET_CODE (addr) != PLUS) 5663 { 5664 rtx tmp = XEXP (addr, 0); 5665 enum rtx_code code = GET_CODE (addr); 5666 5667 /* It only works for UNARY operations. */ 5668 gcc_assert (UNARY_P (addr)); 5669 gcc_assert (GET_CODE (tmp) == UNSPEC); 5670 gcc_assert (oldx); 5671 5672 emit_move_insn 5673 (oldx, 5674 gen_rtx_CONST (SImode, 5675 arc_legitimize_pic_address (tmp, 5676 NULL_RTX))); 5677 5678 emit_insn (gen_rtx_SET (oldx, 5679 gen_rtx_fmt_ee (code, SImode, 5680 oldx, const0_rtx))); 5681 5682 return oldx; 5683 } 5684 else 5685 { 5686 gcc_assert (GET_CODE (addr) == PLUS); 5687 if (GET_CODE (XEXP (addr, 0)) == UNSPEC) 5688 return orig; 5689 } 5690 } 5691 5692 if (GET_CODE (addr) == PLUS) 5693 { 5694 rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1); 5695 5696 base = arc_legitimize_pic_address (op0, oldx); 5697 pat = arc_legitimize_pic_address (op1, 5698 base == oldx ? NULL_RTX : oldx); 5699 5700 if (base == op0 && pat == op1) 5701 return orig; 5702 5703 if (GET_CODE (pat) == CONST_INT) 5704 pat = plus_constant (Pmode, base, INTVAL (pat)); 5705 else 5706 { 5707 if (GET_CODE (pat) == PLUS && CONSTANT_P (XEXP (pat, 1))) 5708 { 5709 base = gen_rtx_PLUS (Pmode, base, XEXP (pat, 0)); 5710 pat = XEXP (pat, 1); 5711 } 5712 pat = gen_rtx_PLUS (Pmode, base, pat); 5713 } 5714 } 5715 } 5716 5717 return pat; 5718 } 5719 5720 /* Output address constant X to FILE, taking PIC into account. */ 5721 5722 static void 5723 arc_output_pic_addr_const (FILE * file, rtx x, int code) 5724 { 5725 char buf[256]; 5726 5727 restart: 5728 switch (GET_CODE (x)) 5729 { 5730 case PC: 5731 if (flag_pic) 5732 putc ('.', file); 5733 else 5734 gcc_unreachable (); 5735 break; 5736 5737 case SYMBOL_REF: 5738 output_addr_const (file, x); 5739 5740 /* Local functions do not get references through the PLT. */ 5741 if (code == 'P' && ! SYMBOL_REF_LOCAL_P (x)) 5742 fputs ("@plt", file); 5743 break; 5744 5745 case LABEL_REF: 5746 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0))); 5747 assemble_name (file, buf); 5748 break; 5749 5750 case CODE_LABEL: 5751 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x)); 5752 assemble_name (file, buf); 5753 break; 5754 5755 case CONST_INT: 5756 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); 5757 break; 5758 5759 case CONST: 5760 arc_output_pic_addr_const (file, XEXP (x, 0), code); 5761 break; 5762 5763 case CONST_DOUBLE: 5764 if (GET_MODE (x) == VOIDmode) 5765 { 5766 /* We can use %d if the number is one word and positive. */ 5767 if (CONST_DOUBLE_HIGH (x)) 5768 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX, 5769 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x)); 5770 else if (CONST_DOUBLE_LOW (x) < 0) 5771 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x)); 5772 else 5773 fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x)); 5774 } 5775 else 5776 /* We can't handle floating point constants; 5777 PRINT_OPERAND must handle them. */ 5778 output_operand_lossage ("floating constant misused"); 5779 break; 5780 5781 case PLUS: 5782 /* FIXME: Not needed here. */ 5783 /* Some assemblers need integer constants to appear last (eg masm). */ 5784 if (GET_CODE (XEXP (x, 0)) == CONST_INT) 5785 { 5786 arc_output_pic_addr_const (file, XEXP (x, 1), code); 5787 fprintf (file, "+"); 5788 arc_output_pic_addr_const (file, XEXP (x, 0), code); 5789 } 5790 else if (GET_CODE (XEXP (x, 1)) == CONST_INT) 5791 { 5792 arc_output_pic_addr_const (file, XEXP (x, 0), code); 5793 if (INTVAL (XEXP (x, 1)) >= 0) 5794 fprintf (file, "+"); 5795 arc_output_pic_addr_const (file, XEXP (x, 1), code); 5796 } 5797 else 5798 gcc_unreachable(); 5799 break; 5800 5801 case MINUS: 5802 /* Avoid outputting things like x-x or x+5-x, 5803 since some assemblers can't handle that. */ 5804 x = simplify_subtraction (x); 5805 if (GET_CODE (x) != MINUS) 5806 goto restart; 5807 5808 arc_output_pic_addr_const (file, XEXP (x, 0), code); 5809 fprintf (file, "-"); 5810 if (GET_CODE (XEXP (x, 1)) == CONST_INT 5811 && INTVAL (XEXP (x, 1)) < 0) 5812 { 5813 fprintf (file, "("); 5814 arc_output_pic_addr_const (file, XEXP (x, 1), code); 5815 fprintf (file, ")"); 5816 } 5817 else 5818 arc_output_pic_addr_const (file, XEXP (x, 1), code); 5819 break; 5820 5821 case ZERO_EXTEND: 5822 case SIGN_EXTEND: 5823 arc_output_pic_addr_const (file, XEXP (x, 0), code); 5824 break; 5825 5826 5827 case UNSPEC: 5828 const char *suffix; 5829 bool pcrel; pcrel = false; 5830 rtx base; base = NULL; 5831 gcc_assert (XVECLEN (x, 0) >= 1); 5832 switch (XINT (x, 1)) 5833 { 5834 case ARC_UNSPEC_GOT: 5835 suffix = "@gotpc", pcrel = true; 5836 break; 5837 case ARC_UNSPEC_GOTOFF: 5838 suffix = "@gotoff"; 5839 break; 5840 case ARC_UNSPEC_GOTOFFPC: 5841 suffix = "@pcl", pcrel = true; 5842 break; 5843 case ARC_UNSPEC_PLT: 5844 suffix = "@plt"; 5845 break; 5846 case UNSPEC_TLS_GD: 5847 suffix = "@tlsgd", pcrel = true; 5848 break; 5849 case UNSPEC_TLS_IE: 5850 suffix = "@tlsie", pcrel = true; 5851 break; 5852 case UNSPEC_TLS_OFF: 5853 if (XVECLEN (x, 0) == 2) 5854 base = XVECEXP (x, 0, 1); 5855 if (SYMBOL_REF_TLS_MODEL (XVECEXP (x, 0, 0)) == TLS_MODEL_LOCAL_EXEC 5856 || (!flag_pic && !base)) 5857 suffix = "@tpoff"; 5858 else 5859 suffix = "@dtpoff"; 5860 break; 5861 default: 5862 suffix = "@invalid"; 5863 output_operand_lossage ("invalid UNSPEC as operand: %d", XINT (x,1)); 5864 break; 5865 } 5866 if (pcrel) 5867 fputs ("pcl,", file); 5868 arc_output_pic_addr_const (file, XVECEXP (x, 0, 0), code); 5869 fputs (suffix, file); 5870 if (base) 5871 arc_output_pic_addr_const (file, base, code); 5872 break; 5873 5874 default: 5875 output_operand_lossage ("invalid expression as operand"); 5876 } 5877 } 5878 5879 #define SYMBOLIC_CONST(X) \ 5880 (GET_CODE (X) == SYMBOL_REF \ 5881 || GET_CODE (X) == LABEL_REF \ 5882 || (GET_CODE (X) == CONST && symbolic_reference_mentioned_p (X))) 5883 5884 /* Emit insns to move operands[1] into operands[0]. */ 5885 5886 static void 5887 prepare_pic_move (rtx *operands, machine_mode) 5888 { 5889 if (GET_CODE (operands[0]) == MEM && SYMBOLIC_CONST (operands[1]) 5890 && flag_pic) 5891 operands[1] = force_reg (Pmode, operands[1]); 5892 else 5893 { 5894 rtx temp = (reload_in_progress ? operands[0] 5895 : flag_pic? gen_reg_rtx (Pmode) : NULL_RTX); 5896 operands[1] = arc_legitimize_pic_address (operands[1], temp); 5897 } 5898 } 5899 5900 5901 /* The function returning the number of words, at the beginning of an 5902 argument, must be put in registers. The returned value must be 5903 zero for arguments that are passed entirely in registers or that 5904 are entirely pushed on the stack. 5905 5906 On some machines, certain arguments must be passed partially in 5907 registers and partially in memory. On these machines, typically 5908 the first N words of arguments are passed in registers, and the 5909 rest on the stack. If a multi-word argument (a `double' or a 5910 structure) crosses that boundary, its first few words must be 5911 passed in registers and the rest must be pushed. This function 5912 tells the compiler when this occurs, and how many of the words 5913 should go in registers. 5914 5915 `FUNCTION_ARG' for these arguments should return the first register 5916 to be used by the caller for this argument; likewise 5917 `FUNCTION_INCOMING_ARG', for the called function. 5918 5919 The function is used to implement macro FUNCTION_ARG_PARTIAL_NREGS. */ 5920 5921 /* If REGNO is the least arg reg available then what is the total number of arg 5922 regs available. */ 5923 #define GPR_REST_ARG_REGS(REGNO) \ 5924 ((REGNO) <= MAX_ARC_PARM_REGS ? MAX_ARC_PARM_REGS - (REGNO) : 0 ) 5925 5926 /* Since arc parm regs are contiguous. */ 5927 #define ARC_NEXT_ARG_REG(REGNO) ( (REGNO) + 1 ) 5928 5929 /* Implement TARGET_ARG_PARTIAL_BYTES. */ 5930 5931 static int 5932 arc_arg_partial_bytes (cumulative_args_t cum_v, machine_mode mode, 5933 tree type, bool named ATTRIBUTE_UNUSED) 5934 { 5935 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); 5936 int bytes = (mode == BLKmode 5937 ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode)); 5938 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; 5939 int arg_num = *cum; 5940 int ret; 5941 5942 arg_num = ROUND_ADVANCE_CUM (arg_num, mode, type); 5943 ret = GPR_REST_ARG_REGS (arg_num); 5944 5945 /* ICEd at function.c:2361, and ret is copied to data->partial */ 5946 ret = (ret >= words ? 0 : ret * UNITS_PER_WORD); 5947 5948 return ret; 5949 } 5950 5951 /* This function is used to control a function argument is passed in a 5952 register, and which register. 5953 5954 The arguments are CUM, of type CUMULATIVE_ARGS, which summarizes 5955 (in a way defined by INIT_CUMULATIVE_ARGS and FUNCTION_ARG_ADVANCE) 5956 all of the previous arguments so far passed in registers; MODE, the 5957 machine mode of the argument; TYPE, the data type of the argument 5958 as a tree node or 0 if that is not known (which happens for C 5959 support library functions); and NAMED, which is 1 for an ordinary 5960 argument and 0 for nameless arguments that correspond to `...' in 5961 the called function's prototype. 5962 5963 The returned value should either be a `reg' RTX for the hard 5964 register in which to pass the argument, or zero to pass the 5965 argument on the stack. 5966 5967 For machines like the Vax and 68000, where normally all arguments 5968 are pushed, zero suffices as a definition. 5969 5970 The usual way to make the ANSI library `stdarg.h' work on a machine 5971 where some arguments are usually passed in registers, is to cause 5972 nameless arguments to be passed on the stack instead. This is done 5973 by making the function return 0 whenever NAMED is 0. 5974 5975 You may use the macro `MUST_PASS_IN_STACK (MODE, TYPE)' in the 5976 definition of this function to determine if this argument is of a 5977 type that must be passed in the stack. If `REG_PARM_STACK_SPACE' 5978 is not defined and the function returns non-zero for such an 5979 argument, the compiler will abort. If `REG_PARM_STACK_SPACE' is 5980 defined, the argument will be computed in the stack and then loaded 5981 into a register. 5982 5983 The function is used to implement macro FUNCTION_ARG. */ 5984 /* On the ARC the first MAX_ARC_PARM_REGS args are normally in registers 5985 and the rest are pushed. */ 5986 5987 static rtx 5988 arc_function_arg (cumulative_args_t cum_v, 5989 machine_mode mode, 5990 const_tree type ATTRIBUTE_UNUSED, 5991 bool named ATTRIBUTE_UNUSED) 5992 { 5993 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); 5994 int arg_num = *cum; 5995 rtx ret; 5996 const char *debstr ATTRIBUTE_UNUSED; 5997 5998 arg_num = ROUND_ADVANCE_CUM (arg_num, mode, type); 5999 /* Return a marker for use in the call instruction. */ 6000 if (mode == VOIDmode) 6001 { 6002 ret = const0_rtx; 6003 debstr = "<0>"; 6004 } 6005 else if (GPR_REST_ARG_REGS (arg_num) > 0) 6006 { 6007 ret = gen_rtx_REG (mode, arg_num); 6008 debstr = reg_names [arg_num]; 6009 } 6010 else 6011 { 6012 ret = NULL_RTX; 6013 debstr = "memory"; 6014 } 6015 return ret; 6016 } 6017 6018 /* The function to update the summarizer variable *CUM to advance past 6019 an argument in the argument list. The values MODE, TYPE and NAMED 6020 describe that argument. Once this is done, the variable *CUM is 6021 suitable for analyzing the *following* argument with 6022 `FUNCTION_ARG', etc. 6023 6024 This function need not do anything if the argument in question was 6025 passed on the stack. The compiler knows how to track the amount of 6026 stack space used for arguments without any special help. 6027 6028 The function is used to implement macro FUNCTION_ARG_ADVANCE. */ 6029 /* For the ARC: the cum set here is passed on to function_arg where we 6030 look at its value and say which reg to use. Strategy: advance the 6031 regnumber here till we run out of arg regs, then set *cum to last 6032 reg. In function_arg, since *cum > last arg reg we would return 0 6033 and thus the arg will end up on the stack. For straddling args of 6034 course function_arg_partial_nregs will come into play. */ 6035 6036 static void 6037 arc_function_arg_advance (cumulative_args_t cum_v, 6038 machine_mode mode, 6039 const_tree type, 6040 bool named ATTRIBUTE_UNUSED) 6041 { 6042 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); 6043 int bytes = (mode == BLKmode 6044 ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode)); 6045 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; 6046 int i; 6047 6048 if (words) 6049 *cum = ROUND_ADVANCE_CUM (*cum, mode, type); 6050 for (i = 0; i < words; i++) 6051 *cum = ARC_NEXT_ARG_REG (*cum); 6052 6053 } 6054 6055 /* Define how to find the value returned by a function. 6056 VALTYPE is the data type of the value (as a tree). 6057 If the precise function being called is known, FN_DECL_OR_TYPE is its 6058 FUNCTION_DECL; otherwise, FN_DECL_OR_TYPE is its type. */ 6059 6060 static rtx 6061 arc_function_value (const_tree valtype, 6062 const_tree fn_decl_or_type ATTRIBUTE_UNUSED, 6063 bool outgoing ATTRIBUTE_UNUSED) 6064 { 6065 machine_mode mode = TYPE_MODE (valtype); 6066 int unsignedp ATTRIBUTE_UNUSED; 6067 6068 unsignedp = TYPE_UNSIGNED (valtype); 6069 if (INTEGRAL_TYPE_P (valtype) || TREE_CODE (valtype) == OFFSET_TYPE) 6070 PROMOTE_MODE (mode, unsignedp, valtype); 6071 return gen_rtx_REG (mode, 0); 6072 } 6073 6074 /* Returns the return address that is used by builtin_return_address. */ 6075 6076 rtx 6077 arc_return_addr_rtx (int count, ATTRIBUTE_UNUSED rtx frame) 6078 { 6079 if (count != 0) 6080 return const0_rtx; 6081 6082 return get_hard_reg_initial_val (Pmode , RETURN_ADDR_REGNUM); 6083 } 6084 6085 /* Determine if a given RTX is a valid constant. We already know this 6086 satisfies CONSTANT_P. */ 6087 6088 bool 6089 arc_legitimate_constant_p (machine_mode mode, rtx x) 6090 { 6091 switch (GET_CODE (x)) 6092 { 6093 case CONST: 6094 if (flag_pic) 6095 { 6096 if (arc_legitimate_pic_addr_p (x)) 6097 return true; 6098 } 6099 return arc_legitimate_constant_p (mode, XEXP (x, 0)); 6100 6101 case SYMBOL_REF: 6102 if (SYMBOL_REF_TLS_MODEL (x)) 6103 return false; 6104 /* Fall through. */ 6105 case LABEL_REF: 6106 if (flag_pic) 6107 return false; 6108 /* Fall through. */ 6109 case CONST_INT: 6110 case CONST_DOUBLE: 6111 return true; 6112 6113 case NEG: 6114 return arc_legitimate_constant_p (mode, XEXP (x, 0)); 6115 6116 case PLUS: 6117 case MINUS: 6118 { 6119 bool t1 = arc_legitimate_constant_p (mode, XEXP (x, 0)); 6120 bool t2 = arc_legitimate_constant_p (mode, XEXP (x, 1)); 6121 6122 return (t1 && t2); 6123 } 6124 6125 case CONST_VECTOR: 6126 switch (mode) 6127 { 6128 case E_V2HImode: 6129 return TARGET_PLUS_DMPY; 6130 case E_V2SImode: 6131 case E_V4HImode: 6132 return TARGET_PLUS_QMACW; 6133 default: 6134 return false; 6135 } 6136 6137 case UNSPEC: 6138 switch (XINT (x, 1)) 6139 { 6140 case UNSPEC_TLS_GD: 6141 case UNSPEC_TLS_OFF: 6142 case UNSPEC_TLS_IE: 6143 return true; 6144 default: 6145 /* Any other unspec ending here are pic related, hence the above 6146 constant pic address checking returned false. */ 6147 return false; 6148 } 6149 /* Fall through. */ 6150 6151 default: 6152 fatal_insn ("unrecognized supposed constant", x); 6153 } 6154 6155 gcc_unreachable (); 6156 } 6157 6158 static bool 6159 arc_legitimate_address_p (machine_mode mode, rtx x, bool strict) 6160 { 6161 if (RTX_OK_FOR_BASE_P (x, strict)) 6162 return true; 6163 if (legitimate_offset_address_p (mode, x, TARGET_INDEXED_LOADS, strict)) 6164 return true; 6165 if (legitimate_scaled_address_p (mode, x, strict)) 6166 return true; 6167 if (LEGITIMATE_SMALL_DATA_ADDRESS_P (x)) 6168 return true; 6169 if (GET_CODE (x) == CONST_INT && LARGE_INT (INTVAL (x))) 6170 return true; 6171 6172 /* When we compile for size avoid const (@sym + offset) 6173 addresses. */ 6174 if (!flag_pic && optimize_size && !reload_completed 6175 && (GET_CODE (x) == CONST) 6176 && (GET_CODE (XEXP (x, 0)) == PLUS) 6177 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF) 6178 && SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0)) == 0 6179 && !SYMBOL_REF_FUNCTION_P (XEXP (XEXP (x, 0), 0))) 6180 { 6181 rtx addend = XEXP (XEXP (x, 0), 1); 6182 gcc_assert (CONST_INT_P (addend)); 6183 HOST_WIDE_INT offset = INTVAL (addend); 6184 6185 /* Allow addresses having a large offset to pass. Anyhow they 6186 will end in a limm. */ 6187 return !(offset > -1024 && offset < 1020); 6188 } 6189 6190 if ((GET_MODE_SIZE (mode) != 16) && CONSTANT_P (x)) 6191 { 6192 return arc_legitimate_constant_p (mode, x); 6193 } 6194 if ((GET_CODE (x) == PRE_DEC || GET_CODE (x) == PRE_INC 6195 || GET_CODE (x) == POST_DEC || GET_CODE (x) == POST_INC) 6196 && RTX_OK_FOR_BASE_P (XEXP (x, 0), strict)) 6197 return true; 6198 /* We're restricted here by the `st' insn. */ 6199 if ((GET_CODE (x) == PRE_MODIFY || GET_CODE (x) == POST_MODIFY) 6200 && GET_CODE (XEXP ((x), 1)) == PLUS 6201 && rtx_equal_p (XEXP ((x), 0), XEXP (XEXP (x, 1), 0)) 6202 && legitimate_offset_address_p (QImode, XEXP (x, 1), 6203 TARGET_AUTO_MODIFY_REG, strict)) 6204 return true; 6205 return false; 6206 } 6207 6208 /* Return true iff ADDR (a legitimate address expression) 6209 has an effect that depends on the machine mode it is used for. */ 6210 6211 static bool 6212 arc_mode_dependent_address_p (const_rtx addr, addr_space_t) 6213 { 6214 /* SYMBOL_REF is not mode dependent: it is either a small data reference, 6215 which is valid for loads and stores, or a limm offset, which is valid for 6216 loads. Scaled indices are scaled by the access mode. */ 6217 if (GET_CODE (addr) == PLUS 6218 && GET_CODE (XEXP ((addr), 0)) == MULT) 6219 return true; 6220 return false; 6221 } 6222 6223 /* Determine if it's legal to put X into the constant pool. */ 6224 6225 static bool 6226 arc_cannot_force_const_mem (machine_mode mode, rtx x) 6227 { 6228 return !arc_legitimate_constant_p (mode, x); 6229 } 6230 6231 /* IDs for all the ARC builtins. */ 6232 6233 enum arc_builtin_id 6234 { 6235 #define DEF_BUILTIN(NAME, N_ARGS, TYPE, ICODE, MASK) \ 6236 ARC_BUILTIN_ ## NAME, 6237 #include "builtins.def" 6238 #undef DEF_BUILTIN 6239 6240 ARC_BUILTIN_COUNT 6241 }; 6242 6243 struct GTY(()) arc_builtin_description 6244 { 6245 enum insn_code icode; 6246 int n_args; 6247 tree fndecl; 6248 }; 6249 6250 static GTY(()) struct arc_builtin_description 6251 arc_bdesc[ARC_BUILTIN_COUNT] = 6252 { 6253 #define DEF_BUILTIN(NAME, N_ARGS, TYPE, ICODE, MASK) \ 6254 { (enum insn_code) CODE_FOR_ ## ICODE, N_ARGS, NULL_TREE }, 6255 #include "builtins.def" 6256 #undef DEF_BUILTIN 6257 }; 6258 6259 /* Transform UP into lowercase and write the result to LO. 6260 You must provide enough space for LO. Return LO. */ 6261 6262 static char* 6263 arc_tolower (char *lo, const char *up) 6264 { 6265 char *lo0 = lo; 6266 6267 for (; *up; up++, lo++) 6268 *lo = TOLOWER (*up); 6269 6270 *lo = '\0'; 6271 6272 return lo0; 6273 } 6274 6275 /* Implement `TARGET_BUILTIN_DECL'. */ 6276 6277 static tree 6278 arc_builtin_decl (unsigned id, bool initialize_p ATTRIBUTE_UNUSED) 6279 { 6280 if (id < ARC_BUILTIN_COUNT) 6281 return arc_bdesc[id].fndecl; 6282 6283 return error_mark_node; 6284 } 6285 6286 static void 6287 arc_init_builtins (void) 6288 { 6289 tree V4HI_type_node; 6290 tree V2SI_type_node; 6291 tree V2HI_type_node; 6292 6293 /* Vector types based on HS SIMD elements. */ 6294 V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode); 6295 V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode); 6296 V2HI_type_node = build_vector_type_for_mode (intHI_type_node, V2HImode); 6297 6298 tree pcvoid_type_node 6299 = build_pointer_type (build_qualified_type (void_type_node, 6300 TYPE_QUAL_CONST)); 6301 tree V8HI_type_node = build_vector_type_for_mode (intHI_type_node, 6302 V8HImode); 6303 6304 tree void_ftype_void 6305 = build_function_type_list (void_type_node, NULL_TREE); 6306 tree int_ftype_int 6307 = build_function_type_list (integer_type_node, integer_type_node, 6308 NULL_TREE); 6309 tree int_ftype_pcvoid_int 6310 = build_function_type_list (integer_type_node, pcvoid_type_node, 6311 integer_type_node, NULL_TREE); 6312 tree void_ftype_usint_usint 6313 = build_function_type_list (void_type_node, long_unsigned_type_node, 6314 long_unsigned_type_node, NULL_TREE); 6315 tree int_ftype_int_int 6316 = build_function_type_list (integer_type_node, integer_type_node, 6317 integer_type_node, NULL_TREE); 6318 tree usint_ftype_usint 6319 = build_function_type_list (long_unsigned_type_node, 6320 long_unsigned_type_node, NULL_TREE); 6321 tree void_ftype_usint 6322 = build_function_type_list (void_type_node, long_unsigned_type_node, 6323 NULL_TREE); 6324 tree int_ftype_void 6325 = build_function_type_list (integer_type_node, void_type_node, 6326 NULL_TREE); 6327 tree void_ftype_int 6328 = build_function_type_list (void_type_node, integer_type_node, 6329 NULL_TREE); 6330 tree int_ftype_short 6331 = build_function_type_list (integer_type_node, short_integer_type_node, 6332 NULL_TREE); 6333 6334 /* Old ARC SIMD types. */ 6335 tree v8hi_ftype_v8hi_v8hi 6336 = build_function_type_list (V8HI_type_node, V8HI_type_node, 6337 V8HI_type_node, NULL_TREE); 6338 tree v8hi_ftype_v8hi_int 6339 = build_function_type_list (V8HI_type_node, V8HI_type_node, 6340 integer_type_node, NULL_TREE); 6341 tree v8hi_ftype_v8hi_int_int 6342 = build_function_type_list (V8HI_type_node, V8HI_type_node, 6343 integer_type_node, integer_type_node, 6344 NULL_TREE); 6345 tree void_ftype_v8hi_int_int 6346 = build_function_type_list (void_type_node, V8HI_type_node, 6347 integer_type_node, integer_type_node, 6348 NULL_TREE); 6349 tree void_ftype_v8hi_int_int_int 6350 = build_function_type_list (void_type_node, V8HI_type_node, 6351 integer_type_node, integer_type_node, 6352 integer_type_node, NULL_TREE); 6353 tree v8hi_ftype_int_int 6354 = build_function_type_list (V8HI_type_node, integer_type_node, 6355 integer_type_node, NULL_TREE); 6356 tree void_ftype_int_int 6357 = build_function_type_list (void_type_node, integer_type_node, 6358 integer_type_node, NULL_TREE); 6359 tree v8hi_ftype_v8hi 6360 = build_function_type_list (V8HI_type_node, V8HI_type_node, 6361 NULL_TREE); 6362 /* ARCv2 SIMD types. */ 6363 tree long_ftype_v4hi_v4hi 6364 = build_function_type_list (long_long_integer_type_node, 6365 V4HI_type_node, V4HI_type_node, NULL_TREE); 6366 tree int_ftype_v2hi_v2hi 6367 = build_function_type_list (integer_type_node, 6368 V2HI_type_node, V2HI_type_node, NULL_TREE); 6369 tree v2si_ftype_v2hi_v2hi 6370 = build_function_type_list (V2SI_type_node, 6371 V2HI_type_node, V2HI_type_node, NULL_TREE); 6372 tree v2hi_ftype_v2hi_v2hi 6373 = build_function_type_list (V2HI_type_node, 6374 V2HI_type_node, V2HI_type_node, NULL_TREE); 6375 tree v2si_ftype_v2si_v2si 6376 = build_function_type_list (V2SI_type_node, 6377 V2SI_type_node, V2SI_type_node, NULL_TREE); 6378 tree v4hi_ftype_v4hi_v4hi 6379 = build_function_type_list (V4HI_type_node, 6380 V4HI_type_node, V4HI_type_node, NULL_TREE); 6381 tree long_ftype_v2si_v2hi 6382 = build_function_type_list (long_long_integer_type_node, 6383 V2SI_type_node, V2HI_type_node, NULL_TREE); 6384 6385 /* Add the builtins. */ 6386 #define DEF_BUILTIN(NAME, N_ARGS, TYPE, ICODE, MASK) \ 6387 { \ 6388 int id = ARC_BUILTIN_ ## NAME; \ 6389 const char *Name = "__builtin_arc_" #NAME; \ 6390 char *name = (char*) alloca (1 + strlen (Name)); \ 6391 \ 6392 gcc_assert (id < ARC_BUILTIN_COUNT); \ 6393 if (MASK) \ 6394 arc_bdesc[id].fndecl \ 6395 = add_builtin_function (arc_tolower(name, Name), TYPE, id, \ 6396 BUILT_IN_MD, NULL, NULL_TREE); \ 6397 } 6398 #include "builtins.def" 6399 #undef DEF_BUILTIN 6400 } 6401 6402 /* Helper to expand __builtin_arc_aligned (void* val, int 6403 alignval). */ 6404 6405 static rtx 6406 arc_expand_builtin_aligned (tree exp) 6407 { 6408 tree arg0 = CALL_EXPR_ARG (exp, 0); 6409 tree arg1 = CALL_EXPR_ARG (exp, 1); 6410 fold (arg1); 6411 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, EXPAND_NORMAL); 6412 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, EXPAND_NORMAL); 6413 6414 if (!CONST_INT_P (op1)) 6415 { 6416 /* If we can't fold the alignment to a constant integer 6417 whilst optimizing, this is probably a user error. */ 6418 if (optimize) 6419 warning (0, "__builtin_arc_aligned with non-constant alignment"); 6420 } 6421 else 6422 { 6423 HOST_WIDE_INT alignTest = INTVAL (op1); 6424 /* Check alignTest is positive, and a power of two. */ 6425 if (alignTest <= 0 || alignTest != (alignTest & -alignTest)) 6426 { 6427 error ("invalid alignment value for __builtin_arc_aligned"); 6428 return NULL_RTX; 6429 } 6430 6431 if (CONST_INT_P (op0)) 6432 { 6433 HOST_WIDE_INT pnt = INTVAL (op0); 6434 6435 if ((pnt & (alignTest - 1)) == 0) 6436 return const1_rtx; 6437 } 6438 else 6439 { 6440 unsigned align = get_pointer_alignment (arg0); 6441 unsigned numBits = alignTest * BITS_PER_UNIT; 6442 6443 if (align && align >= numBits) 6444 return const1_rtx; 6445 /* Another attempt to ascertain alignment. Check the type 6446 we are pointing to. */ 6447 if (POINTER_TYPE_P (TREE_TYPE (arg0)) 6448 && TYPE_ALIGN (TREE_TYPE (TREE_TYPE (arg0))) >= numBits) 6449 return const1_rtx; 6450 } 6451 } 6452 6453 /* Default to false. */ 6454 return const0_rtx; 6455 } 6456 6457 /* Helper arc_expand_builtin, generates a pattern for the given icode 6458 and arguments. */ 6459 6460 static rtx_insn * 6461 apply_GEN_FCN (enum insn_code icode, rtx *arg) 6462 { 6463 switch (insn_data[icode].n_generator_args) 6464 { 6465 case 0: 6466 return GEN_FCN (icode) (); 6467 case 1: 6468 return GEN_FCN (icode) (arg[0]); 6469 case 2: 6470 return GEN_FCN (icode) (arg[0], arg[1]); 6471 case 3: 6472 return GEN_FCN (icode) (arg[0], arg[1], arg[2]); 6473 case 4: 6474 return GEN_FCN (icode) (arg[0], arg[1], arg[2], arg[3]); 6475 case 5: 6476 return GEN_FCN (icode) (arg[0], arg[1], arg[2], arg[3], arg[4]); 6477 default: 6478 gcc_unreachable (); 6479 } 6480 } 6481 6482 /* Expand an expression EXP that calls a built-in function, 6483 with result going to TARGET if that's convenient 6484 (and in mode MODE if that's convenient). 6485 SUBTARGET may be used as the target for computing one of EXP's operands. 6486 IGNORE is nonzero if the value is to be ignored. */ 6487 6488 static rtx 6489 arc_expand_builtin (tree exp, 6490 rtx target, 6491 rtx subtarget ATTRIBUTE_UNUSED, 6492 machine_mode mode ATTRIBUTE_UNUSED, 6493 int ignore ATTRIBUTE_UNUSED) 6494 { 6495 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0); 6496 unsigned int id = DECL_FUNCTION_CODE (fndecl); 6497 const struct arc_builtin_description *d = &arc_bdesc[id]; 6498 int i, j, n_args = call_expr_nargs (exp); 6499 rtx pat = NULL_RTX; 6500 rtx xop[5]; 6501 enum insn_code icode = d->icode; 6502 machine_mode tmode = insn_data[icode].operand[0].mode; 6503 int nonvoid; 6504 tree arg0; 6505 tree arg1; 6506 tree arg2; 6507 tree arg3; 6508 rtx op0; 6509 rtx op1; 6510 rtx op2; 6511 rtx op3; 6512 rtx op4; 6513 machine_mode mode0; 6514 machine_mode mode1; 6515 machine_mode mode2; 6516 machine_mode mode3; 6517 machine_mode mode4; 6518 6519 if (id >= ARC_BUILTIN_COUNT) 6520 internal_error ("bad builtin fcode"); 6521 6522 /* 1st part: Expand special builtins. */ 6523 switch (id) 6524 { 6525 case ARC_BUILTIN_NOP: 6526 emit_insn (gen_nopv ()); 6527 return NULL_RTX; 6528 6529 case ARC_BUILTIN_RTIE: 6530 case ARC_BUILTIN_SYNC: 6531 case ARC_BUILTIN_BRK: 6532 case ARC_BUILTIN_SWI: 6533 case ARC_BUILTIN_UNIMP_S: 6534 gcc_assert (icode != 0); 6535 emit_insn (GEN_FCN (icode) (const1_rtx)); 6536 return NULL_RTX; 6537 6538 case ARC_BUILTIN_ALIGNED: 6539 return arc_expand_builtin_aligned (exp); 6540 6541 case ARC_BUILTIN_CLRI: 6542 target = gen_reg_rtx (SImode); 6543 emit_insn (gen_clri (target, const1_rtx)); 6544 return target; 6545 6546 case ARC_BUILTIN_TRAP_S: 6547 case ARC_BUILTIN_SLEEP: 6548 arg0 = CALL_EXPR_ARG (exp, 0); 6549 fold (arg0); 6550 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, EXPAND_NORMAL); 6551 6552 gcc_assert (icode != 0); 6553 emit_insn (GEN_FCN (icode) (op0)); 6554 return NULL_RTX; 6555 6556 case ARC_BUILTIN_VDORUN: 6557 case ARC_BUILTIN_VDIRUN: 6558 arg0 = CALL_EXPR_ARG (exp, 0); 6559 arg1 = CALL_EXPR_ARG (exp, 1); 6560 op0 = expand_expr (arg0, NULL_RTX, SImode, EXPAND_NORMAL); 6561 op1 = expand_expr (arg1, NULL_RTX, SImode, EXPAND_NORMAL); 6562 6563 target = gen_rtx_REG (SImode, (id == ARC_BUILTIN_VDIRUN) ? 131 : 139); 6564 6565 mode0 = insn_data[icode].operand[1].mode; 6566 mode1 = insn_data[icode].operand[2].mode; 6567 6568 if (!insn_data[icode].operand[1].predicate (op0, mode0)) 6569 op0 = copy_to_mode_reg (mode0, op0); 6570 6571 if (!insn_data[icode].operand[2].predicate (op1, mode1)) 6572 op1 = copy_to_mode_reg (mode1, op1); 6573 6574 pat = GEN_FCN (icode) (target, op0, op1); 6575 if (!pat) 6576 return NULL_RTX; 6577 6578 emit_insn (pat); 6579 return NULL_RTX; 6580 6581 case ARC_BUILTIN_VDIWR: 6582 case ARC_BUILTIN_VDOWR: 6583 arg0 = CALL_EXPR_ARG (exp, 0); 6584 arg1 = CALL_EXPR_ARG (exp, 1); 6585 op0 = expand_expr (arg0, NULL_RTX, SImode, EXPAND_NORMAL); 6586 op1 = expand_expr (arg1, NULL_RTX, SImode, EXPAND_NORMAL); 6587 6588 if (!CONST_INT_P (op0) 6589 || !(UNSIGNED_INT3 (INTVAL (op0)))) 6590 error ("operand 1 should be an unsigned 3-bit immediate"); 6591 6592 mode1 = insn_data[icode].operand[1].mode; 6593 6594 if (icode == CODE_FOR_vdiwr_insn) 6595 target = gen_rtx_REG (SImode, 6596 ARC_FIRST_SIMD_DMA_CONFIG_IN_REG + INTVAL (op0)); 6597 else if (icode == CODE_FOR_vdowr_insn) 6598 target = gen_rtx_REG (SImode, 6599 ARC_FIRST_SIMD_DMA_CONFIG_OUT_REG + INTVAL (op0)); 6600 else 6601 gcc_unreachable (); 6602 6603 if (!insn_data[icode].operand[2].predicate (op1, mode1)) 6604 op1 = copy_to_mode_reg (mode1, op1); 6605 6606 pat = GEN_FCN (icode) (target, op1); 6607 if (!pat) 6608 return NULL_RTX; 6609 6610 emit_insn (pat); 6611 return NULL_RTX; 6612 6613 case ARC_BUILTIN_VASRW: 6614 case ARC_BUILTIN_VSR8: 6615 case ARC_BUILTIN_VSR8AW: 6616 arg0 = CALL_EXPR_ARG (exp, 0); 6617 arg1 = CALL_EXPR_ARG (exp, 1); 6618 op0 = expand_expr (arg0, NULL_RTX, V8HImode, EXPAND_NORMAL); 6619 op1 = expand_expr (arg1, NULL_RTX, SImode, EXPAND_NORMAL); 6620 op2 = gen_rtx_REG (V8HImode, ARC_FIRST_SIMD_VR_REG); 6621 6622 target = gen_reg_rtx (V8HImode); 6623 mode0 = insn_data[icode].operand[1].mode; 6624 mode1 = insn_data[icode].operand[2].mode; 6625 6626 if (!insn_data[icode].operand[1].predicate (op0, mode0)) 6627 op0 = copy_to_mode_reg (mode0, op0); 6628 6629 if ((!insn_data[icode].operand[2].predicate (op1, mode1)) 6630 || !(UNSIGNED_INT3 (INTVAL (op1)))) 6631 error ("operand 2 should be an unsigned 3-bit value (I0-I7)"); 6632 6633 pat = GEN_FCN (icode) (target, op0, op1, op2); 6634 if (!pat) 6635 return NULL_RTX; 6636 6637 emit_insn (pat); 6638 return target; 6639 6640 case ARC_BUILTIN_VLD32WH: 6641 case ARC_BUILTIN_VLD32WL: 6642 case ARC_BUILTIN_VLD64: 6643 case ARC_BUILTIN_VLD32: 6644 rtx src_vreg; 6645 icode = d->icode; 6646 arg0 = CALL_EXPR_ARG (exp, 0); /* source vreg. */ 6647 arg1 = CALL_EXPR_ARG (exp, 1); /* [I]0-7. */ 6648 arg2 = CALL_EXPR_ARG (exp, 2); /* u8. */ 6649 6650 src_vreg = expand_expr (arg0, NULL_RTX, V8HImode, EXPAND_NORMAL); 6651 op0 = expand_expr (arg1, NULL_RTX, SImode, EXPAND_NORMAL); 6652 op1 = expand_expr (arg2, NULL_RTX, SImode, EXPAND_NORMAL); 6653 op2 = gen_rtx_REG (V8HImode, ARC_FIRST_SIMD_VR_REG); 6654 6655 /* target <- src vreg. */ 6656 emit_insn (gen_move_insn (target, src_vreg)); 6657 6658 /* target <- vec_concat: target, mem (Ib, u8). */ 6659 mode0 = insn_data[icode].operand[3].mode; 6660 mode1 = insn_data[icode].operand[1].mode; 6661 6662 if ((!insn_data[icode].operand[3].predicate (op0, mode0)) 6663 || !(UNSIGNED_INT3 (INTVAL (op0)))) 6664 error ("operand 1 should be an unsigned 3-bit value (I0-I7)"); 6665 6666 if ((!insn_data[icode].operand[1].predicate (op1, mode1)) 6667 || !(UNSIGNED_INT8 (INTVAL (op1)))) 6668 error ("operand 2 should be an unsigned 8-bit value"); 6669 6670 pat = GEN_FCN (icode) (target, op1, op2, op0); 6671 if (!pat) 6672 return NULL_RTX; 6673 6674 emit_insn (pat); 6675 return target; 6676 6677 case ARC_BUILTIN_VLD64W: 6678 case ARC_BUILTIN_VLD128: 6679 arg0 = CALL_EXPR_ARG (exp, 0); /* dest vreg. */ 6680 arg1 = CALL_EXPR_ARG (exp, 1); /* [I]0-7. */ 6681 6682 op0 = gen_rtx_REG (V8HImode, ARC_FIRST_SIMD_VR_REG); 6683 op1 = expand_expr (arg0, NULL_RTX, SImode, EXPAND_NORMAL); 6684 op2 = expand_expr (arg1, NULL_RTX, SImode, EXPAND_NORMAL); 6685 6686 /* target <- src vreg. */ 6687 target = gen_reg_rtx (V8HImode); 6688 6689 /* target <- vec_concat: target, mem (Ib, u8). */ 6690 mode0 = insn_data[icode].operand[1].mode; 6691 mode1 = insn_data[icode].operand[2].mode; 6692 mode2 = insn_data[icode].operand[3].mode; 6693 6694 if ((!insn_data[icode].operand[2].predicate (op1, mode1)) 6695 || !(UNSIGNED_INT3 (INTVAL (op1)))) 6696 error ("operand 1 should be an unsigned 3-bit value (I0-I7)"); 6697 6698 if ((!insn_data[icode].operand[3].predicate (op2, mode2)) 6699 || !(UNSIGNED_INT8 (INTVAL (op2)))) 6700 error ("operand 2 should be an unsigned 8-bit value"); 6701 6702 pat = GEN_FCN (icode) (target, op0, op1, op2); 6703 6704 if (!pat) 6705 return NULL_RTX; 6706 6707 emit_insn (pat); 6708 return target; 6709 6710 case ARC_BUILTIN_VST128: 6711 case ARC_BUILTIN_VST64: 6712 arg0 = CALL_EXPR_ARG (exp, 0); /* src vreg. */ 6713 arg1 = CALL_EXPR_ARG (exp, 1); /* [I]0-7. */ 6714 arg2 = CALL_EXPR_ARG (exp, 2); /* u8. */ 6715 6716 op0 = gen_rtx_REG (V8HImode, ARC_FIRST_SIMD_VR_REG); 6717 op1 = expand_expr (arg1, NULL_RTX, SImode, EXPAND_NORMAL); 6718 op2 = expand_expr (arg2, NULL_RTX, SImode, EXPAND_NORMAL); 6719 op3 = expand_expr (arg0, NULL_RTX, V8HImode, EXPAND_NORMAL); 6720 6721 mode0 = insn_data[icode].operand[0].mode; 6722 mode1 = insn_data[icode].operand[1].mode; 6723 mode2 = insn_data[icode].operand[2].mode; 6724 mode3 = insn_data[icode].operand[3].mode; 6725 6726 if ((!insn_data[icode].operand[1].predicate (op1, mode1)) 6727 || !(UNSIGNED_INT3 (INTVAL (op1)))) 6728 error ("operand 2 should be an unsigned 3-bit value (I0-I7)"); 6729 6730 if ((!insn_data[icode].operand[2].predicate (op2, mode2)) 6731 || !(UNSIGNED_INT8 (INTVAL (op2)))) 6732 error ("operand 3 should be an unsigned 8-bit value"); 6733 6734 if (!insn_data[icode].operand[3].predicate (op3, mode3)) 6735 op3 = copy_to_mode_reg (mode3, op3); 6736 6737 pat = GEN_FCN (icode) (op0, op1, op2, op3); 6738 if (!pat) 6739 return NULL_RTX; 6740 6741 emit_insn (pat); 6742 return NULL_RTX; 6743 6744 case ARC_BUILTIN_VST16_N: 6745 case ARC_BUILTIN_VST32_N: 6746 arg0 = CALL_EXPR_ARG (exp, 0); /* source vreg. */ 6747 arg1 = CALL_EXPR_ARG (exp, 1); /* u3. */ 6748 arg2 = CALL_EXPR_ARG (exp, 2); /* [I]0-7. */ 6749 arg3 = CALL_EXPR_ARG (exp, 3); /* u8. */ 6750 6751 op0 = expand_expr (arg3, NULL_RTX, SImode, EXPAND_NORMAL); 6752 op1 = gen_rtx_REG (V8HImode, ARC_FIRST_SIMD_VR_REG); 6753 op2 = expand_expr (arg2, NULL_RTX, SImode, EXPAND_NORMAL); 6754 op3 = expand_expr (arg0, NULL_RTX, V8HImode, EXPAND_NORMAL); 6755 op4 = expand_expr (arg1, NULL_RTX, SImode, EXPAND_NORMAL); 6756 6757 mode0 = insn_data[icode].operand[0].mode; 6758 mode2 = insn_data[icode].operand[2].mode; 6759 mode3 = insn_data[icode].operand[3].mode; 6760 mode4 = insn_data[icode].operand[4].mode; 6761 6762 /* Do some correctness checks for the operands. */ 6763 if ((!insn_data[icode].operand[0].predicate (op0, mode0)) 6764 || !(UNSIGNED_INT8 (INTVAL (op0)))) 6765 error ("operand 4 should be an unsigned 8-bit value (0-255)"); 6766 6767 if ((!insn_data[icode].operand[2].predicate (op2, mode2)) 6768 || !(UNSIGNED_INT3 (INTVAL (op2)))) 6769 error ("operand 3 should be an unsigned 3-bit value (I0-I7)"); 6770 6771 if (!insn_data[icode].operand[3].predicate (op3, mode3)) 6772 op3 = copy_to_mode_reg (mode3, op3); 6773 6774 if ((!insn_data[icode].operand[4].predicate (op4, mode4)) 6775 || !(UNSIGNED_INT3 (INTVAL (op4)))) 6776 error ("operand 2 should be an unsigned 3-bit value (subreg 0-7)"); 6777 else if (icode == CODE_FOR_vst32_n_insn 6778 && ((INTVAL (op4) % 2) != 0)) 6779 error ("operand 2 should be an even 3-bit value (subreg 0,2,4,6)"); 6780 6781 pat = GEN_FCN (icode) (op0, op1, op2, op3, op4); 6782 if (!pat) 6783 return NULL_RTX; 6784 6785 emit_insn (pat); 6786 return NULL_RTX; 6787 6788 default: 6789 break; 6790 } 6791 6792 /* 2nd part: Expand regular builtins. */ 6793 if (icode == 0) 6794 internal_error ("bad builtin fcode"); 6795 6796 nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node; 6797 j = 0; 6798 6799 if (nonvoid) 6800 { 6801 if (target == NULL_RTX 6802 || GET_MODE (target) != tmode 6803 || !insn_data[icode].operand[0].predicate (target, tmode)) 6804 { 6805 target = gen_reg_rtx (tmode); 6806 } 6807 xop[j++] = target; 6808 } 6809 6810 gcc_assert (n_args <= 4); 6811 for (i = 0; i < n_args; i++, j++) 6812 { 6813 tree arg = CALL_EXPR_ARG (exp, i); 6814 machine_mode mode = insn_data[icode].operand[j].mode; 6815 rtx op = expand_expr (arg, NULL_RTX, mode, EXPAND_NORMAL); 6816 machine_mode opmode = GET_MODE (op); 6817 char c = insn_data[icode].operand[j].constraint[0]; 6818 6819 /* SIMD extension requires exact immediate operand match. */ 6820 if ((id > ARC_BUILTIN_SIMD_BEGIN) 6821 && (id < ARC_BUILTIN_SIMD_END) 6822 && (c != 'v') 6823 && (c != 'r')) 6824 { 6825 if (!CONST_INT_P (op)) 6826 error ("builtin requires an immediate for operand %d", j); 6827 switch (c) 6828 { 6829 case 'L': 6830 if (!satisfies_constraint_L (op)) 6831 error ("operand %d should be a 6 bit unsigned immediate", j); 6832 break; 6833 case 'P': 6834 if (!satisfies_constraint_P (op)) 6835 error ("operand %d should be a 8 bit unsigned immediate", j); 6836 break; 6837 case 'K': 6838 if (!satisfies_constraint_K (op)) 6839 error ("operand %d should be a 3 bit unsigned immediate", j); 6840 break; 6841 default: 6842 error ("unknown builtin immediate operand type for operand %d", 6843 j); 6844 } 6845 } 6846 6847 if (CONST_INT_P (op)) 6848 opmode = mode; 6849 6850 if ((opmode == SImode) && (mode == HImode)) 6851 { 6852 opmode = HImode; 6853 op = gen_lowpart (HImode, op); 6854 } 6855 6856 /* In case the insn wants input operands in modes different from 6857 the result, abort. */ 6858 gcc_assert (opmode == mode || opmode == VOIDmode); 6859 6860 if (!insn_data[icode].operand[i + nonvoid].predicate (op, mode)) 6861 op = copy_to_mode_reg (mode, op); 6862 6863 xop[j] = op; 6864 } 6865 6866 pat = apply_GEN_FCN (icode, xop); 6867 if (pat == NULL_RTX) 6868 return NULL_RTX; 6869 6870 emit_insn (pat); 6871 6872 if (nonvoid) 6873 return target; 6874 else 6875 return const0_rtx; 6876 } 6877 6878 /* Returns true if the operands[opno] is a valid compile-time constant to be 6879 used as register number in the code for builtins. Else it flags an error 6880 and returns false. */ 6881 6882 bool 6883 check_if_valid_regno_const (rtx *operands, int opno) 6884 { 6885 6886 switch (GET_CODE (operands[opno])) 6887 { 6888 case SYMBOL_REF : 6889 case CONST : 6890 case CONST_INT : 6891 return true; 6892 default: 6893 error ("register number must be a compile-time constant. Try giving higher optimization levels"); 6894 break; 6895 } 6896 return false; 6897 } 6898 6899 /* Return true if it is ok to make a tail-call to DECL. */ 6900 6901 static bool 6902 arc_function_ok_for_sibcall (tree decl, 6903 tree exp ATTRIBUTE_UNUSED) 6904 { 6905 tree attrs = NULL_TREE; 6906 6907 /* Never tailcall from an ISR routine - it needs a special exit sequence. */ 6908 if (ARC_INTERRUPT_P (arc_compute_function_type (cfun))) 6909 return false; 6910 6911 if (decl) 6912 { 6913 attrs = TYPE_ATTRIBUTES (TREE_TYPE (decl)); 6914 6915 if (lookup_attribute ("jli_always", attrs)) 6916 return false; 6917 if (lookup_attribute ("jli_fixed", attrs)) 6918 return false; 6919 if (lookup_attribute ("secure_call", attrs)) 6920 return false; 6921 } 6922 6923 /* Everything else is ok. */ 6924 return true; 6925 } 6926 6927 /* Output code to add DELTA to the first argument, and then jump 6928 to FUNCTION. Used for C++ multiple inheritance. */ 6929 6930 static void 6931 arc_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED, 6932 HOST_WIDE_INT delta, 6933 HOST_WIDE_INT vcall_offset, 6934 tree function) 6935 { 6936 int mi_delta = delta; 6937 const char *const mi_op = mi_delta < 0 ? "sub" : "add"; 6938 int shift = 0; 6939 int this_regno 6940 = aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function) ? 1 : 0; 6941 rtx fnaddr; 6942 6943 if (mi_delta < 0) 6944 mi_delta = - mi_delta; 6945 6946 /* Add DELTA. When possible use a plain add, otherwise load it into 6947 a register first. */ 6948 6949 while (mi_delta != 0) 6950 { 6951 if ((mi_delta & (3 << shift)) == 0) 6952 shift += 2; 6953 else 6954 { 6955 asm_fprintf (file, "\t%s\t%s, %s, %d\n", 6956 mi_op, reg_names[this_regno], reg_names[this_regno], 6957 mi_delta & (0xff << shift)); 6958 mi_delta &= ~(0xff << shift); 6959 shift += 8; 6960 } 6961 } 6962 6963 /* If needed, add *(*THIS + VCALL_OFFSET) to THIS. */ 6964 if (vcall_offset != 0) 6965 { 6966 /* ld r12,[this] --> temp = *this 6967 add r12,r12,vcall_offset --> temp = *(*this + vcall_offset) 6968 ld r12,[r12] 6969 add this,this,r12 --> this+ = *(*this + vcall_offset) */ 6970 asm_fprintf (file, "\tld\t%s, [%s]\n", 6971 ARC_TEMP_SCRATCH_REG, reg_names[this_regno]); 6972 asm_fprintf (file, "\tadd\t%s, %s, " HOST_WIDE_INT_PRINT_DEC "\n", 6973 ARC_TEMP_SCRATCH_REG, ARC_TEMP_SCRATCH_REG, vcall_offset); 6974 asm_fprintf (file, "\tld\t%s, [%s]\n", 6975 ARC_TEMP_SCRATCH_REG, ARC_TEMP_SCRATCH_REG); 6976 asm_fprintf (file, "\tadd\t%s, %s, %s\n", reg_names[this_regno], 6977 reg_names[this_regno], ARC_TEMP_SCRATCH_REG); 6978 } 6979 6980 fnaddr = XEXP (DECL_RTL (function), 0); 6981 6982 if (arc_is_longcall_p (fnaddr)) 6983 { 6984 if (flag_pic) 6985 { 6986 asm_fprintf (file, "\tld\t%s, [pcl, @", 6987 ARC_TEMP_SCRATCH_REG); 6988 assemble_name (file, XSTR (fnaddr, 0)); 6989 fputs ("@gotpc]\n", file); 6990 asm_fprintf (file, "\tj\t[%s]", ARC_TEMP_SCRATCH_REG); 6991 } 6992 else 6993 { 6994 fputs ("\tj\t@", file); 6995 assemble_name (file, XSTR (fnaddr, 0)); 6996 } 6997 } 6998 else 6999 { 7000 fputs ("\tb\t@", file); 7001 assemble_name (file, XSTR (fnaddr, 0)); 7002 if (flag_pic) 7003 fputs ("@plt\n", file); 7004 } 7005 fputc ('\n', file); 7006 } 7007 7008 /* Return true if a 32 bit "long_call" should be generated for 7009 this calling SYM_REF. We generate a long_call if the function: 7010 7011 a. has an __attribute__((long call)) 7012 or b. the -mlong-calls command line switch has been specified 7013 7014 However we do not generate a long call if the function has an 7015 __attribute__ ((short_call)) or __attribute__ ((medium_call)) 7016 7017 This function will be called by C fragments contained in the machine 7018 description file. */ 7019 7020 bool 7021 arc_is_longcall_p (rtx sym_ref) 7022 { 7023 if (GET_CODE (sym_ref) != SYMBOL_REF) 7024 return false; 7025 7026 return (SYMBOL_REF_LONG_CALL_P (sym_ref) 7027 || (TARGET_LONG_CALLS_SET 7028 && !SYMBOL_REF_SHORT_CALL_P (sym_ref) 7029 && !SYMBOL_REF_MEDIUM_CALL_P (sym_ref))); 7030 7031 } 7032 7033 /* Likewise for short calls. */ 7034 7035 bool 7036 arc_is_shortcall_p (rtx sym_ref) 7037 { 7038 if (GET_CODE (sym_ref) != SYMBOL_REF) 7039 return false; 7040 7041 return (SYMBOL_REF_SHORT_CALL_P (sym_ref) 7042 || (!TARGET_LONG_CALLS_SET && !TARGET_MEDIUM_CALLS 7043 && !SYMBOL_REF_LONG_CALL_P (sym_ref) 7044 && !SYMBOL_REF_MEDIUM_CALL_P (sym_ref))); 7045 7046 } 7047 7048 /* Worker function for TARGET_RETURN_IN_MEMORY. */ 7049 7050 static bool 7051 arc_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED) 7052 { 7053 if (AGGREGATE_TYPE_P (type) || TREE_ADDRESSABLE (type)) 7054 return true; 7055 else 7056 { 7057 HOST_WIDE_INT size = int_size_in_bytes (type); 7058 return (size == -1 || size > (TARGET_V2 ? 16 : 8)); 7059 } 7060 } 7061 7062 static bool 7063 arc_pass_by_reference (cumulative_args_t ca_v ATTRIBUTE_UNUSED, 7064 machine_mode mode ATTRIBUTE_UNUSED, 7065 const_tree type, 7066 bool named ATTRIBUTE_UNUSED) 7067 { 7068 return (type != 0 7069 && (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST 7070 || TREE_ADDRESSABLE (type))); 7071 } 7072 7073 /* Implement TARGET_CAN_USE_DOLOOP_P. */ 7074 7075 static bool 7076 arc_can_use_doloop_p (const widest_int &, 7077 const widest_int &iterations_max, 7078 unsigned int loop_depth, bool entered_at_top) 7079 { 7080 /* Considering limitations in the hardware, only use doloop 7081 for innermost loops which must be entered from the top. */ 7082 if (loop_depth > 1 || !entered_at_top) 7083 return false; 7084 7085 /* Check for lp_count width boundary. */ 7086 if (arc_lpcwidth != 32 7087 && (wi::gtu_p (iterations_max, ((1 << arc_lpcwidth) - 1)) 7088 || wi::eq_p (iterations_max, 0))) 7089 return false; 7090 return true; 7091 } 7092 7093 /* NULL if INSN insn is valid within a low-overhead loop. Otherwise 7094 return why doloop cannot be applied. */ 7095 7096 static const char * 7097 arc_invalid_within_doloop (const rtx_insn *insn) 7098 { 7099 if (CALL_P (insn)) 7100 return "Function call in the loop."; 7101 7102 /* FIXME! add here all the ZOL exceptions. */ 7103 return NULL; 7104 } 7105 7106 /* Return true if a load instruction (CONSUMER) uses the same address as a 7107 store instruction (PRODUCER). This function is used to avoid st/ld 7108 address hazard in ARC700 cores. */ 7109 bool 7110 arc_store_addr_hazard_p (rtx_insn* producer, rtx_insn* consumer) 7111 { 7112 rtx in_set, out_set; 7113 rtx out_addr, in_addr; 7114 7115 if (!producer) 7116 return false; 7117 7118 if (!consumer) 7119 return false; 7120 7121 /* Peel the producer and the consumer for the address. */ 7122 out_set = single_set (producer); 7123 if (out_set) 7124 { 7125 out_addr = SET_DEST (out_set); 7126 if (!out_addr) 7127 return false; 7128 if (GET_CODE (out_addr) == ZERO_EXTEND 7129 || GET_CODE (out_addr) == SIGN_EXTEND) 7130 out_addr = XEXP (out_addr, 0); 7131 7132 if (!MEM_P (out_addr)) 7133 return false; 7134 7135 in_set = single_set (consumer); 7136 if (in_set) 7137 { 7138 in_addr = SET_SRC (in_set); 7139 if (!in_addr) 7140 return false; 7141 if (GET_CODE (in_addr) == ZERO_EXTEND 7142 || GET_CODE (in_addr) == SIGN_EXTEND) 7143 in_addr = XEXP (in_addr, 0); 7144 7145 if (!MEM_P (in_addr)) 7146 return false; 7147 /* Get rid of the MEM and check if the addresses are 7148 equivalent. */ 7149 in_addr = XEXP (in_addr, 0); 7150 out_addr = XEXP (out_addr, 0); 7151 7152 return exp_equiv_p (in_addr, out_addr, 0, true); 7153 } 7154 } 7155 return false; 7156 } 7157 7158 /* The same functionality as arc_hazard. It is called in machine 7159 reorg before any other optimization. Hence, the NOP size is taken 7160 into account when doing branch shortening. */ 7161 7162 static void 7163 workaround_arc_anomaly (void) 7164 { 7165 rtx_insn *insn, *succ0; 7166 7167 /* For any architecture: call arc_hazard here. */ 7168 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 7169 { 7170 succ0 = next_real_insn (insn); 7171 if (arc_hazard (insn, succ0)) 7172 { 7173 emit_insn_before (gen_nopv (), succ0); 7174 } 7175 } 7176 7177 if (TARGET_ARC700) 7178 { 7179 rtx_insn *succ1; 7180 7181 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 7182 { 7183 succ0 = next_real_insn (insn); 7184 if (arc_store_addr_hazard_p (insn, succ0)) 7185 { 7186 emit_insn_after (gen_nopv (), insn); 7187 emit_insn_after (gen_nopv (), insn); 7188 continue; 7189 } 7190 7191 /* Avoid adding nops if the instruction between the ST and LD is 7192 a call or jump. */ 7193 succ1 = next_real_insn (succ0); 7194 if (succ0 && !JUMP_P (succ0) && !CALL_P (succ0) 7195 && arc_store_addr_hazard_p (insn, succ1)) 7196 emit_insn_after (gen_nopv (), insn); 7197 } 7198 } 7199 } 7200 7201 /* A callback for the hw-doloop pass. Called when a loop we have discovered 7202 turns out not to be optimizable; we have to split the loop_end pattern into 7203 a subtract and a test. */ 7204 7205 static void 7206 hwloop_fail (hwloop_info loop) 7207 { 7208 rtx test; 7209 rtx insn = loop->loop_end; 7210 7211 if (TARGET_DBNZ 7212 && (loop->length && (loop->length <= ARC_MAX_LOOP_LENGTH)) 7213 && REG_P (loop->iter_reg)) 7214 { 7215 /* TARGET_V2 core3 has dbnz instructions. */ 7216 test = gen_dbnz (loop->iter_reg, loop->start_label); 7217 insn = emit_jump_insn_before (test, loop->loop_end); 7218 } 7219 else if (REG_P (loop->iter_reg) && (REGNO (loop->iter_reg) == LP_COUNT)) 7220 { 7221 /* We have the lp_count as loop iterator, try to use it. */ 7222 emit_insn_before (gen_loop_fail (), loop->loop_end); 7223 test = gen_rtx_NE (VOIDmode, gen_rtx_REG (CC_ZNmode, CC_REG), 7224 const0_rtx); 7225 test = gen_rtx_IF_THEN_ELSE (VOIDmode, test, 7226 gen_rtx_LABEL_REF (Pmode, loop->start_label), 7227 pc_rtx); 7228 insn = emit_jump_insn_before (gen_rtx_SET (pc_rtx, test), 7229 loop->loop_end); 7230 } 7231 else 7232 { 7233 emit_insn_before (gen_addsi3 (loop->iter_reg, 7234 loop->iter_reg, 7235 constm1_rtx), 7236 loop->loop_end); 7237 test = gen_rtx_NE (VOIDmode, loop->iter_reg, const0_rtx); 7238 insn = emit_jump_insn_before (gen_cbranchsi4 (test, 7239 loop->iter_reg, 7240 const0_rtx, 7241 loop->start_label), 7242 loop->loop_end); 7243 } 7244 JUMP_LABEL (insn) = loop->start_label; 7245 LABEL_NUSES (loop->start_label)++; 7246 delete_insn (loop->loop_end); 7247 } 7248 7249 /* Optimize LOOP. */ 7250 7251 static bool 7252 hwloop_optimize (hwloop_info loop) 7253 { 7254 int i; 7255 edge entry_edge; 7256 basic_block entry_bb, bb; 7257 rtx iter_reg, end_label; 7258 rtx_insn *insn, *seq, *entry_after, *last_insn; 7259 unsigned int length; 7260 bool need_fix = false; 7261 rtx lp_reg = gen_rtx_REG (SImode, LP_COUNT); 7262 7263 if (loop->depth > 1) 7264 { 7265 if (dump_file) 7266 fprintf (dump_file, ";; loop %d is not innermost\n", 7267 loop->loop_no); 7268 return false; 7269 } 7270 7271 if (!loop->incoming_dest) 7272 { 7273 if (dump_file) 7274 fprintf (dump_file, ";; loop %d has more than one entry\n", 7275 loop->loop_no); 7276 return false; 7277 } 7278 7279 if (loop->incoming_dest != loop->head) 7280 { 7281 if (dump_file) 7282 fprintf (dump_file, ";; loop %d is not entered from head\n", 7283 loop->loop_no); 7284 return false; 7285 } 7286 7287 if (loop->has_call || loop->has_asm) 7288 { 7289 if (dump_file) 7290 fprintf (dump_file, ";; loop %d has invalid insn\n", 7291 loop->loop_no); 7292 return false; 7293 } 7294 7295 /* Scan all the blocks to make sure they don't use iter_reg. */ 7296 if (loop->iter_reg_used || loop->iter_reg_used_outside) 7297 { 7298 if (dump_file) 7299 fprintf (dump_file, ";; loop %d uses iterator\n", 7300 loop->loop_no); 7301 return false; 7302 } 7303 7304 /* Check if start_label appears before doloop_end. */ 7305 length = 0; 7306 for (insn = loop->start_label; 7307 insn && insn != loop->loop_end; 7308 insn = NEXT_INSN (insn)) 7309 { 7310 length += NONDEBUG_INSN_P (insn) ? get_attr_length (insn) : 0; 7311 if (JUMP_TABLES_IN_TEXT_SECTION 7312 && JUMP_TABLE_DATA_P (insn)) 7313 { 7314 if (dump_file) 7315 fprintf (dump_file, ";; loop %d has a jump table\n", 7316 loop->loop_no); 7317 return false; 7318 } 7319 } 7320 7321 if (!insn) 7322 { 7323 if (dump_file) 7324 fprintf (dump_file, ";; loop %d start_label not before loop_end\n", 7325 loop->loop_no); 7326 return false; 7327 } 7328 7329 loop->length = length; 7330 if (loop->length > ARC_MAX_LOOP_LENGTH) 7331 { 7332 if (dump_file) 7333 fprintf (dump_file, ";; loop %d too long\n", loop->loop_no); 7334 return false; 7335 } 7336 else if (!loop->length) 7337 { 7338 if (dump_file) 7339 fprintf (dump_file, ";; loop %d is empty\n", loop->loop_no); 7340 return false; 7341 } 7342 7343 /* Check if we use a register or not. */ 7344 if (!REG_P (loop->iter_reg)) 7345 { 7346 if (dump_file) 7347 fprintf (dump_file, ";; loop %d iterator is MEM\n", 7348 loop->loop_no); 7349 return false; 7350 } 7351 7352 /* Check if loop register is lpcount. */ 7353 if (REG_P (loop->iter_reg) && (REGNO (loop->iter_reg)) != LP_COUNT) 7354 { 7355 if (dump_file) 7356 fprintf (dump_file, ";; loop %d doesn't use lp_count as loop" 7357 " iterator\n", 7358 loop->loop_no); 7359 /* This loop doesn't use the lp_count, check though if we can 7360 fix it. */ 7361 if (TEST_HARD_REG_BIT (loop->regs_set_in_loop, LP_COUNT) 7362 /* In very unique cases we may have LP_COUNT alive. */ 7363 || (loop->incoming_src 7364 && REGNO_REG_SET_P (df_get_live_out (loop->incoming_src), 7365 LP_COUNT))) 7366 return false; 7367 else 7368 need_fix = true; 7369 } 7370 7371 /* Check for control like instruction as the last instruction of a 7372 ZOL. */ 7373 bb = loop->tail; 7374 last_insn = PREV_INSN (loop->loop_end); 7375 7376 while (1) 7377 { 7378 for (; last_insn != BB_HEAD (bb); 7379 last_insn = PREV_INSN (last_insn)) 7380 if (NONDEBUG_INSN_P (last_insn)) 7381 break; 7382 7383 if (last_insn != BB_HEAD (bb)) 7384 break; 7385 7386 if (single_pred_p (bb) 7387 && single_pred_edge (bb)->flags & EDGE_FALLTHRU 7388 && single_pred (bb) != ENTRY_BLOCK_PTR_FOR_FN (cfun)) 7389 { 7390 bb = single_pred (bb); 7391 last_insn = BB_END (bb); 7392 continue; 7393 } 7394 else 7395 { 7396 last_insn = NULL; 7397 break; 7398 } 7399 } 7400 7401 if (!last_insn) 7402 { 7403 if (dump_file) 7404 fprintf (dump_file, ";; loop %d has no last instruction\n", 7405 loop->loop_no); 7406 return false; 7407 } 7408 7409 if ((TARGET_ARC600_FAMILY || TARGET_HS) 7410 && INSN_P (last_insn) 7411 && (JUMP_P (last_insn) || CALL_P (last_insn) 7412 || GET_CODE (PATTERN (last_insn)) == SEQUENCE 7413 /* At this stage we can have (insn (clobber (mem:BLK 7414 (reg)))) instructions, ignore them. */ 7415 || (GET_CODE (PATTERN (last_insn)) != CLOBBER 7416 && (get_attr_type (last_insn) == TYPE_BRCC 7417 || get_attr_type (last_insn) == TYPE_BRCC_NO_DELAY_SLOT)))) 7418 { 7419 if (loop->length + 2 > ARC_MAX_LOOP_LENGTH) 7420 { 7421 if (dump_file) 7422 fprintf (dump_file, ";; loop %d too long\n", loop->loop_no); 7423 return false; 7424 } 7425 if (dump_file) 7426 fprintf (dump_file, ";; loop %d has a control like last insn;" 7427 "add a nop\n", 7428 loop->loop_no); 7429 7430 last_insn = emit_insn_after (gen_nopv (), last_insn); 7431 } 7432 7433 if (LABEL_P (last_insn)) 7434 { 7435 if (dump_file) 7436 fprintf (dump_file, ";; loop %d has a label as last insn;" 7437 "add a nop\n", 7438 loop->loop_no); 7439 last_insn = emit_insn_after (gen_nopv (), last_insn); 7440 } 7441 7442 /* SAVE_NOTE is used by haifa scheduler. However, we are after it 7443 and we can use it to indicate the last ZOL instruction cannot be 7444 part of a delay slot. */ 7445 add_reg_note (last_insn, REG_SAVE_NOTE, GEN_INT (2)); 7446 7447 loop->last_insn = last_insn; 7448 7449 /* Get the loop iteration register. */ 7450 iter_reg = loop->iter_reg; 7451 7452 gcc_assert (REG_P (iter_reg)); 7453 7454 entry_edge = NULL; 7455 7456 FOR_EACH_VEC_SAFE_ELT (loop->incoming, i, entry_edge) 7457 if (entry_edge->flags & EDGE_FALLTHRU) 7458 break; 7459 7460 if (entry_edge == NULL) 7461 { 7462 if (dump_file) 7463 fprintf (dump_file, ";; loop %d has no fallthru edge jumping" 7464 "into the loop\n", 7465 loop->loop_no); 7466 return false; 7467 } 7468 /* The loop is good. */ 7469 end_label = gen_label_rtx (); 7470 loop->end_label = end_label; 7471 7472 /* Place the zero_cost_loop_start instruction before the loop. */ 7473 entry_bb = entry_edge->src; 7474 7475 start_sequence (); 7476 7477 if (need_fix) 7478 { 7479 /* The loop uses a R-register, but the lp_count is free, thus 7480 use lp_count. */ 7481 emit_insn (gen_movsi (lp_reg, iter_reg)); 7482 SET_HARD_REG_BIT (loop->regs_set_in_loop, LP_COUNT); 7483 iter_reg = lp_reg; 7484 if (dump_file) 7485 { 7486 fprintf (dump_file, ";; fix loop %d to use lp_count\n", 7487 loop->loop_no); 7488 } 7489 } 7490 7491 insn = emit_insn (gen_arc_lp (iter_reg, 7492 loop->start_label, 7493 loop->end_label)); 7494 7495 seq = get_insns (); 7496 end_sequence (); 7497 7498 entry_after = BB_END (entry_bb); 7499 if (!single_succ_p (entry_bb) || vec_safe_length (loop->incoming) > 1 7500 || !entry_after) 7501 { 7502 basic_block new_bb; 7503 edge e; 7504 edge_iterator ei; 7505 7506 emit_insn_before (seq, BB_HEAD (loop->head)); 7507 seq = emit_label_before (gen_label_rtx (), seq); 7508 new_bb = create_basic_block (seq, insn, entry_bb); 7509 FOR_EACH_EDGE (e, ei, loop->incoming) 7510 { 7511 if (!(e->flags & EDGE_FALLTHRU)) 7512 redirect_edge_and_branch_force (e, new_bb); 7513 else 7514 redirect_edge_succ (e, new_bb); 7515 } 7516 7517 make_edge (new_bb, loop->head, 0); 7518 } 7519 else 7520 { 7521 #if 0 7522 while (DEBUG_INSN_P (entry_after) 7523 || (NOTE_P (entry_after) 7524 && NOTE_KIND (entry_after) != NOTE_INSN_BASIC_BLOCK)) 7525 entry_after = NEXT_INSN (entry_after); 7526 #endif 7527 entry_after = next_nonnote_nondebug_insn_bb (entry_after); 7528 7529 gcc_assert (entry_after); 7530 emit_insn_before (seq, entry_after); 7531 } 7532 7533 delete_insn (loop->loop_end); 7534 /* Insert the loop end label before the last instruction of the 7535 loop. */ 7536 emit_label_after (end_label, loop->last_insn); 7537 /* Make sure we mark the begining and end label as used. */ 7538 LABEL_NUSES (loop->end_label)++; 7539 LABEL_NUSES (loop->start_label)++; 7540 7541 return true; 7542 } 7543 7544 /* A callback for the hw-doloop pass. This function examines INSN; if 7545 it is a loop_end pattern we recognize, return the reg rtx for the 7546 loop counter. Otherwise, return NULL_RTX. */ 7547 7548 static rtx 7549 hwloop_pattern_reg (rtx_insn *insn) 7550 { 7551 rtx reg; 7552 7553 if (!JUMP_P (insn) || recog_memoized (insn) != CODE_FOR_loop_end) 7554 return NULL_RTX; 7555 7556 reg = SET_DEST (XVECEXP (PATTERN (insn), 0, 1)); 7557 if (!REG_P (reg)) 7558 return NULL_RTX; 7559 return reg; 7560 } 7561 7562 static struct hw_doloop_hooks arc_doloop_hooks = 7563 { 7564 hwloop_pattern_reg, 7565 hwloop_optimize, 7566 hwloop_fail 7567 }; 7568 7569 /* Run from machine_dependent_reorg, this pass looks for doloop_end insns 7570 and tries to rewrite the RTL of these loops so that proper Blackfin 7571 hardware loops are generated. */ 7572 7573 static void 7574 arc_reorg_loops (void) 7575 { 7576 reorg_loops (true, &arc_doloop_hooks); 7577 } 7578 7579 /* Scan all calls and add symbols to be emitted in the jli section if 7580 needed. */ 7581 7582 static void 7583 jli_call_scan (void) 7584 { 7585 rtx_insn *insn; 7586 7587 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 7588 { 7589 if (!CALL_P (insn)) 7590 continue; 7591 7592 rtx pat = PATTERN (insn); 7593 if (GET_CODE (pat) == COND_EXEC) 7594 pat = COND_EXEC_CODE (pat); 7595 pat = XVECEXP (pat, 0, 0); 7596 if (GET_CODE (pat) == SET) 7597 pat = SET_SRC (pat); 7598 7599 pat = XEXP (XEXP (pat, 0), 0); 7600 if (GET_CODE (pat) == SYMBOL_REF 7601 && arc_is_jli_call_p (pat)) 7602 arc_add_jli_section (pat); 7603 } 7604 } 7605 7606 /* Add padding if necessary to avoid a mispredict. A return could 7607 happen immediately after the function start. A call/return and 7608 return/return must be 6 bytes apart to avoid mispredict. */ 7609 7610 static void 7611 pad_return (void) 7612 { 7613 rtx_insn *insn; 7614 long offset; 7615 7616 if (!TARGET_PAD_RETURN) 7617 return; 7618 7619 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 7620 { 7621 rtx_insn *prev0 = prev_active_insn (insn); 7622 bool wantlong = false; 7623 7624 if (!INSN_P (insn) || GET_CODE (PATTERN (insn)) != SIMPLE_RETURN) 7625 continue; 7626 7627 if (!prev0) 7628 { 7629 prev0 = emit_insn_before (gen_nopv (), insn); 7630 /* REG_SAVE_NOTE is used by Haifa scheduler, we are in reorg 7631 so it is safe to reuse it for forcing a particular length 7632 for an instruction. */ 7633 add_reg_note (prev0, REG_SAVE_NOTE, GEN_INT (1)); 7634 emit_insn_before (gen_nopv (), insn); 7635 continue; 7636 } 7637 offset = get_attr_length (prev0); 7638 7639 if (get_attr_length (prev0) == 2 7640 && get_attr_iscompact (prev0) != ISCOMPACT_TRUE) 7641 { 7642 /* Force long version of the insn. */ 7643 wantlong = true; 7644 offset += 2; 7645 } 7646 7647 rtx_insn *prev = prev_active_insn (prev0); 7648 if (prev) 7649 offset += get_attr_length (prev); 7650 7651 prev = prev_active_insn (prev); 7652 if (prev) 7653 offset += get_attr_length (prev); 7654 7655 switch (offset) 7656 { 7657 case 2: 7658 prev = emit_insn_before (gen_nopv (), insn); 7659 add_reg_note (prev, REG_SAVE_NOTE, GEN_INT (1)); 7660 break; 7661 case 4: 7662 emit_insn_before (gen_nopv (), insn); 7663 break; 7664 default: 7665 continue; 7666 } 7667 7668 if (wantlong) 7669 add_reg_note (prev0, REG_SAVE_NOTE, GEN_INT (1)); 7670 7671 /* Emit a blockage to avoid delay slot scheduling. */ 7672 emit_insn_before (gen_blockage (), insn); 7673 } 7674 } 7675 7676 static int arc_reorg_in_progress = 0; 7677 7678 /* ARC's machince specific reorg function. */ 7679 7680 static void 7681 arc_reorg (void) 7682 { 7683 rtx_insn *insn; 7684 rtx pattern; 7685 rtx pc_target; 7686 long offset; 7687 int changed; 7688 7689 cfun->machine->arc_reorg_started = 1; 7690 arc_reorg_in_progress = 1; 7691 7692 compute_bb_for_insn (); 7693 7694 df_analyze (); 7695 7696 /* Doloop optimization. */ 7697 arc_reorg_loops (); 7698 7699 workaround_arc_anomaly (); 7700 jli_call_scan (); 7701 pad_return (); 7702 7703 /* FIXME: should anticipate ccfsm action, generate special patterns for 7704 to-be-deleted branches that have no delay slot and have at least the 7705 length of the size increase forced on other insns that are conditionalized. 7706 This can also have an insn_list inside that enumerates insns which are 7707 not actually conditionalized because the destinations are dead in the 7708 not-execute case. 7709 Could also tag branches that we want to be unaligned if they get no delay 7710 slot, or even ones that we don't want to do delay slot sheduling for 7711 because we can unalign them. 7712 7713 However, there are cases when conditional execution is only possible after 7714 delay slot scheduling: 7715 7716 - If a delay slot is filled with a nocond/set insn from above, the previous 7717 basic block can become elegible for conditional execution. 7718 - If a delay slot is filled with a nocond insn from the fall-through path, 7719 the branch with that delay slot can become eligble for conditional 7720 execution (however, with the same sort of data flow analysis that dbr 7721 does, we could have figured out before that we don't need to 7722 conditionalize this insn.) 7723 - If a delay slot insn is filled with an insn from the target, the 7724 target label gets its uses decremented (even deleted if falling to zero), 7725 thus possibly creating more condexec opportunities there. 7726 Therefore, we should still be prepared to apply condexec optimization on 7727 non-prepared branches if the size increase of conditionalized insns is no 7728 more than the size saved from eliminating the branch. An invocation option 7729 could also be used to reserve a bit of extra size for condbranches so that 7730 this'll work more often (could also test in arc_reorg if the block is 7731 'close enough' to be eligible for condexec to make this likely, and 7732 estimate required size increase). */ 7733 /* Generate BRcc insns, by combining cmp and Bcc insns wherever possible. */ 7734 if (TARGET_NO_BRCC_SET) 7735 return; 7736 7737 do 7738 { 7739 init_insn_lengths(); 7740 changed = 0; 7741 7742 if (optimize > 1 && !TARGET_NO_COND_EXEC) 7743 { 7744 arc_ifcvt (); 7745 unsigned int flags = pass_data_arc_ifcvt.todo_flags_finish; 7746 df_finish_pass ((flags & TODO_df_verify) != 0); 7747 7748 if (dump_file) 7749 { 7750 fprintf (dump_file, ";; After if conversion:\n\n"); 7751 print_rtl (dump_file, get_insns ()); 7752 } 7753 } 7754 7755 /* Call shorten_branches to calculate the insn lengths. */ 7756 shorten_branches (get_insns()); 7757 cfun->machine->ccfsm_current_insn = NULL_RTX; 7758 7759 if (!INSN_ADDRESSES_SET_P()) 7760 fatal_error (input_location, "Insn addresses not set after shorten_branches"); 7761 7762 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 7763 { 7764 rtx label; 7765 enum attr_type insn_type; 7766 7767 /* If a non-jump insn (or a casesi jump table), continue. */ 7768 if (GET_CODE (insn) != JUMP_INSN || 7769 GET_CODE (PATTERN (insn)) == ADDR_VEC 7770 || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC) 7771 continue; 7772 7773 /* If we already have a brcc, note if it is suitable for brcc_s. 7774 Be a bit generous with the brcc_s range so that we can take 7775 advantage of any code shortening from delay slot scheduling. */ 7776 if (recog_memoized (insn) == CODE_FOR_cbranchsi4_scratch) 7777 { 7778 rtx pat = PATTERN (insn); 7779 rtx op = XEXP (SET_SRC (XVECEXP (pat, 0, 0)), 0); 7780 rtx *ccp = &XEXP (XVECEXP (pat, 0, 1), 0); 7781 7782 offset = branch_dest (insn) - INSN_ADDRESSES (INSN_UID (insn)); 7783 if ((offset >= -140 && offset < 140) 7784 && rtx_equal_p (XEXP (op, 1), const0_rtx) 7785 && compact_register_operand (XEXP (op, 0), VOIDmode) 7786 && equality_comparison_operator (op, VOIDmode)) 7787 PUT_MODE (*ccp, CC_Zmode); 7788 else if (GET_MODE (*ccp) == CC_Zmode) 7789 PUT_MODE (*ccp, CC_ZNmode); 7790 continue; 7791 } 7792 if ((insn_type = get_attr_type (insn)) == TYPE_BRCC 7793 || insn_type == TYPE_BRCC_NO_DELAY_SLOT) 7794 continue; 7795 7796 /* OK. so we have a jump insn. */ 7797 /* We need to check that it is a bcc. */ 7798 /* Bcc => set (pc) (if_then_else ) */ 7799 pattern = PATTERN (insn); 7800 if (GET_CODE (pattern) != SET 7801 || GET_CODE (SET_SRC (pattern)) != IF_THEN_ELSE 7802 || ANY_RETURN_P (XEXP (SET_SRC (pattern), 1))) 7803 continue; 7804 7805 /* Now check if the jump is beyond the s9 range. */ 7806 if (CROSSING_JUMP_P (insn)) 7807 continue; 7808 offset = branch_dest (insn) - INSN_ADDRESSES (INSN_UID (insn)); 7809 7810 if(offset > 253 || offset < -254) 7811 continue; 7812 7813 pc_target = SET_SRC (pattern); 7814 7815 /* Avoid FPU instructions. */ 7816 if ((GET_MODE (XEXP (XEXP (pc_target, 0), 0)) == CC_FPUmode) 7817 || (GET_MODE (XEXP (XEXP (pc_target, 0), 0)) == CC_FPU_UNEQmode)) 7818 continue; 7819 7820 /* Now go back and search for the set cc insn. */ 7821 7822 label = XEXP (pc_target, 1); 7823 7824 { 7825 rtx pat; 7826 rtx_insn *scan, *link_insn = NULL; 7827 7828 for (scan = PREV_INSN (insn); 7829 scan && GET_CODE (scan) != CODE_LABEL; 7830 scan = PREV_INSN (scan)) 7831 { 7832 if (! INSN_P (scan)) 7833 continue; 7834 pat = PATTERN (scan); 7835 if (GET_CODE (pat) == SET 7836 && cc_register (SET_DEST (pat), VOIDmode)) 7837 { 7838 link_insn = scan; 7839 break; 7840 } 7841 } 7842 if (!link_insn) 7843 continue; 7844 else 7845 /* Check if this is a data dependency. */ 7846 { 7847 rtx op, cc_clob_rtx, op0, op1, brcc_insn, note; 7848 rtx cmp0, cmp1; 7849 7850 /* Ok this is the set cc. copy args here. */ 7851 op = XEXP (pc_target, 0); 7852 7853 op0 = cmp0 = XEXP (SET_SRC (pat), 0); 7854 op1 = cmp1 = XEXP (SET_SRC (pat), 1); 7855 if (GET_CODE (op0) == ZERO_EXTRACT 7856 && XEXP (op0, 1) == const1_rtx 7857 && (GET_CODE (op) == EQ 7858 || GET_CODE (op) == NE)) 7859 { 7860 /* btst / b{eq,ne} -> bbit{0,1} */ 7861 op0 = XEXP (cmp0, 0); 7862 op1 = XEXP (cmp0, 2); 7863 } 7864 else if (!register_operand (op0, VOIDmode) 7865 || !general_operand (op1, VOIDmode)) 7866 continue; 7867 /* Be careful not to break what cmpsfpx_raw is 7868 trying to create for checking equality of 7869 single-precision floats. */ 7870 else if (TARGET_SPFP 7871 && GET_MODE (op0) == SFmode 7872 && GET_MODE (op1) == SFmode) 7873 continue; 7874 7875 /* None of the two cmp operands should be set between the 7876 cmp and the branch. */ 7877 if (reg_set_between_p (op0, link_insn, insn)) 7878 continue; 7879 7880 if (reg_set_between_p (op1, link_insn, insn)) 7881 continue; 7882 7883 /* Since the MODE check does not work, check that this is 7884 CC reg's last set location before insn, and also no 7885 instruction between the cmp and branch uses the 7886 condition codes. */ 7887 if ((reg_set_between_p (SET_DEST (pat), link_insn, insn)) 7888 || (reg_used_between_p (SET_DEST (pat), link_insn, insn))) 7889 continue; 7890 7891 /* CC reg should be dead after insn. */ 7892 if (!find_regno_note (insn, REG_DEAD, CC_REG)) 7893 continue; 7894 7895 op = gen_rtx_fmt_ee (GET_CODE (op), 7896 GET_MODE (op), cmp0, cmp1); 7897 /* If we create a LIMM where there was none before, 7898 we only benefit if we can avoid a scheduling bubble 7899 for the ARC600. Otherwise, we'd only forgo chances 7900 at short insn generation, and risk out-of-range 7901 branches. */ 7902 if (!brcc_nolimm_operator (op, VOIDmode) 7903 && !long_immediate_operand (op1, VOIDmode) 7904 && (TARGET_ARC700 7905 || next_active_insn (link_insn) != insn)) 7906 continue; 7907 7908 /* Emit bbit / brcc (or brcc_s if possible). 7909 CC_Zmode indicates that brcc_s is possible. */ 7910 7911 if (op0 != cmp0) 7912 cc_clob_rtx = gen_rtx_REG (CC_ZNmode, CC_REG); 7913 else if ((offset >= -140 && offset < 140) 7914 && rtx_equal_p (op1, const0_rtx) 7915 && compact_register_operand (op0, VOIDmode) 7916 && (GET_CODE (op) == EQ 7917 || GET_CODE (op) == NE)) 7918 cc_clob_rtx = gen_rtx_REG (CC_Zmode, CC_REG); 7919 else 7920 cc_clob_rtx = gen_rtx_REG (CCmode, CC_REG); 7921 7922 brcc_insn 7923 = gen_rtx_IF_THEN_ELSE (VOIDmode, op, label, pc_rtx); 7924 brcc_insn = gen_rtx_SET (pc_rtx, brcc_insn); 7925 cc_clob_rtx = gen_rtx_CLOBBER (VOIDmode, cc_clob_rtx); 7926 brcc_insn 7927 = gen_rtx_PARALLEL 7928 (VOIDmode, gen_rtvec (2, brcc_insn, cc_clob_rtx)); 7929 brcc_insn = emit_jump_insn_before (brcc_insn, insn); 7930 7931 JUMP_LABEL (brcc_insn) = JUMP_LABEL (insn); 7932 note = find_reg_note (insn, REG_BR_PROB, 0); 7933 if (note) 7934 { 7935 XEXP (note, 1) = REG_NOTES (brcc_insn); 7936 REG_NOTES (brcc_insn) = note; 7937 } 7938 note = find_reg_note (link_insn, REG_DEAD, op0); 7939 if (note) 7940 { 7941 remove_note (link_insn, note); 7942 XEXP (note, 1) = REG_NOTES (brcc_insn); 7943 REG_NOTES (brcc_insn) = note; 7944 } 7945 note = find_reg_note (link_insn, REG_DEAD, op1); 7946 if (note) 7947 { 7948 XEXP (note, 1) = REG_NOTES (brcc_insn); 7949 REG_NOTES (brcc_insn) = note; 7950 } 7951 7952 changed = 1; 7953 7954 /* Delete the bcc insn. */ 7955 set_insn_deleted (insn); 7956 7957 /* Delete the cmp insn. */ 7958 set_insn_deleted (link_insn); 7959 7960 } 7961 } 7962 } 7963 /* Clear out insn_addresses. */ 7964 INSN_ADDRESSES_FREE (); 7965 7966 } while (changed); 7967 7968 if (INSN_ADDRESSES_SET_P()) 7969 fatal_error (input_location, "insn addresses not freed"); 7970 7971 arc_reorg_in_progress = 0; 7972 } 7973 7974 /* Check if the operands are valid for BRcc.d generation 7975 Valid Brcc.d patterns are 7976 Brcc.d b, c, s9 7977 Brcc.d b, u6, s9 7978 7979 For cc={GT, LE, GTU, LEU}, u6=63 can not be allowed, 7980 since they are encoded by the assembler as {GE, LT, HS, LS} 64, which 7981 does not have a delay slot 7982 7983 Assumed precondition: Second operand is either a register or a u6 value. */ 7984 7985 bool 7986 valid_brcc_with_delay_p (rtx *operands) 7987 { 7988 if (optimize_size && GET_MODE (operands[4]) == CC_Zmode) 7989 return false; 7990 return brcc_nolimm_operator (operands[0], VOIDmode); 7991 } 7992 7993 /* Implement TARGET_IN_SMALL_DATA_P. Return true if it would be safe to 7994 access DECL using %gp_rel(...)($gp). */ 7995 7996 static bool 7997 arc_in_small_data_p (const_tree decl) 7998 { 7999 HOST_WIDE_INT size; 8000 tree attr; 8001 8002 /* Only variables are going into small data area. */ 8003 if (TREE_CODE (decl) != VAR_DECL) 8004 return false; 8005 8006 if (TARGET_NO_SDATA_SET) 8007 return false; 8008 8009 /* Disable sdata references to weak variables. */ 8010 if (DECL_WEAK (decl)) 8011 return false; 8012 8013 /* Don't put constants into the small data section: we want them to 8014 be in ROM rather than RAM. */ 8015 if (TREE_READONLY (decl)) 8016 return false; 8017 8018 /* To ensure -mvolatile-cache works ld.di does not have a 8019 gp-relative variant. */ 8020 if (!TARGET_VOLATILE_CACHE_SET 8021 && TREE_THIS_VOLATILE (decl)) 8022 return false; 8023 8024 /* Likewise for uncached data. */ 8025 attr = TYPE_ATTRIBUTES (TREE_TYPE (decl)); 8026 if (lookup_attribute ("uncached", attr)) 8027 return false; 8028 8029 /* and for aux regs. */ 8030 attr = DECL_ATTRIBUTES (decl); 8031 if (lookup_attribute ("aux", attr)) 8032 return false; 8033 8034 if (DECL_SECTION_NAME (decl) != 0) 8035 { 8036 const char *name = DECL_SECTION_NAME (decl); 8037 if (strcmp (name, ".sdata") == 0 8038 || strcmp (name, ".sbss") == 0) 8039 return true; 8040 } 8041 /* If it's not public, there's no need to put it in the small data 8042 section. */ 8043 else if (TREE_PUBLIC (decl)) 8044 { 8045 size = int_size_in_bytes (TREE_TYPE (decl)); 8046 return (size > 0 && size <= g_switch_value); 8047 } 8048 return false; 8049 } 8050 8051 /* Return true if X is a small data address that can be rewritten 8052 as a gp+symref. */ 8053 8054 static bool 8055 arc_rewrite_small_data_p (const_rtx x) 8056 { 8057 if (GET_CODE (x) == CONST) 8058 x = XEXP (x, 0); 8059 8060 if (GET_CODE (x) == PLUS) 8061 { 8062 if (GET_CODE (XEXP (x, 1)) == CONST_INT) 8063 x = XEXP (x, 0); 8064 } 8065 8066 if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_SMALL_P (x)) 8067 { 8068 gcc_assert (SYMBOL_REF_TLS_MODEL (x) == 0); 8069 return true; 8070 } 8071 return false; 8072 } 8073 8074 /* If possible, rewrite OP so that it refers to small data using 8075 explicit relocations. */ 8076 8077 static rtx 8078 arc_rewrite_small_data_1 (rtx op) 8079 { 8080 rtx rgp = gen_rtx_REG (Pmode, SDATA_BASE_REGNUM); 8081 op = copy_insn (op); 8082 subrtx_ptr_iterator::array_type array; 8083 FOR_EACH_SUBRTX_PTR (iter, array, &op, ALL) 8084 { 8085 rtx *loc = *iter; 8086 if (arc_rewrite_small_data_p (*loc)) 8087 { 8088 *loc = gen_rtx_PLUS (Pmode, rgp, *loc); 8089 iter.skip_subrtxes (); 8090 } 8091 else if (GET_CODE (*loc) == PLUS 8092 && rtx_equal_p (XEXP (*loc, 0), rgp)) 8093 iter.skip_subrtxes (); 8094 } 8095 return op; 8096 } 8097 8098 rtx 8099 arc_rewrite_small_data (rtx op) 8100 { 8101 op = arc_rewrite_small_data_1 (op); 8102 8103 /* Check if we fit small data constraints. */ 8104 if (MEM_P (op) 8105 && !LEGITIMATE_SMALL_DATA_ADDRESS_P (XEXP (op, 0))) 8106 { 8107 rtx addr = XEXP (op, 0); 8108 rtx tmp = gen_reg_rtx (Pmode); 8109 emit_move_insn (tmp, addr); 8110 op = replace_equiv_address_nv (op, tmp); 8111 } 8112 return op; 8113 } 8114 8115 /* Return true if OP refers to small data symbols directly, not through 8116 a PLUS. */ 8117 8118 bool 8119 small_data_pattern (rtx op, machine_mode) 8120 { 8121 if (GET_CODE (op) == SEQUENCE) 8122 return false; 8123 8124 rtx rgp = gen_rtx_REG (Pmode, SDATA_BASE_REGNUM); 8125 subrtx_iterator::array_type array; 8126 FOR_EACH_SUBRTX (iter, array, op, ALL) 8127 { 8128 const_rtx x = *iter; 8129 if (GET_CODE (x) == PLUS 8130 && rtx_equal_p (XEXP (x, 0), rgp)) 8131 iter.skip_subrtxes (); 8132 else if (arc_rewrite_small_data_p (x)) 8133 return true; 8134 } 8135 return false; 8136 } 8137 8138 /* Return true if OP is an acceptable memory operand for ARCompact 8139 16-bit gp-relative load instructions. 8140 op shd look like : [r26, symref@sda] 8141 i.e. (mem (plus (reg 26) (symref with smalldata flag set)) 8142 */ 8143 /* volatile cache option still to be handled. */ 8144 8145 bool 8146 compact_sda_memory_operand (rtx op, machine_mode mode, bool short_p) 8147 { 8148 rtx addr; 8149 int size; 8150 tree decl = NULL_TREE; 8151 int align = 0; 8152 int mask = 0; 8153 8154 /* Eliminate non-memory operations. */ 8155 if (GET_CODE (op) != MEM) 8156 return false; 8157 8158 if (mode == VOIDmode) 8159 mode = GET_MODE (op); 8160 8161 size = GET_MODE_SIZE (mode); 8162 8163 /* dword operations really put out 2 instructions, so eliminate them. */ 8164 if (size > UNITS_PER_WORD) 8165 return false; 8166 8167 /* Decode the address now. */ 8168 addr = XEXP (op, 0); 8169 8170 if (!LEGITIMATE_SMALL_DATA_ADDRESS_P (addr)) 8171 return false; 8172 8173 if (!short_p || size == 1) 8174 return true; 8175 8176 /* Now check for the alignment, the short loads using gp require the 8177 addresses to be aligned. */ 8178 if (GET_CODE (XEXP (addr, 1)) == SYMBOL_REF) 8179 decl = SYMBOL_REF_DECL (XEXP (addr, 1)); 8180 else if (GET_CODE (XEXP (XEXP (XEXP (addr, 1), 0), 0)) == SYMBOL_REF) 8181 decl = SYMBOL_REF_DECL (XEXP (XEXP (XEXP (addr, 1), 0), 0)); 8182 if (decl) 8183 align = DECL_ALIGN (decl); 8184 align = align / BITS_PER_UNIT; 8185 8186 switch (mode) 8187 { 8188 case E_HImode: 8189 mask = 1; 8190 break; 8191 default: 8192 mask = 3; 8193 break; 8194 } 8195 8196 if (align && ((align & mask) == 0)) 8197 return true; 8198 return false; 8199 } 8200 8201 /* Return TRUE if PAT is accessing an aux-reg. */ 8202 8203 static bool 8204 arc_is_aux_reg_p (rtx pat) 8205 { 8206 tree attrs = NULL_TREE; 8207 tree addr; 8208 8209 if (!MEM_P (pat)) 8210 return false; 8211 8212 /* Get the memory attributes. */ 8213 addr = MEM_EXPR (pat); 8214 if (!addr) 8215 return false; 8216 8217 /* Get the attributes. */ 8218 if (TREE_CODE (addr) == VAR_DECL) 8219 attrs = DECL_ATTRIBUTES (addr); 8220 else if (TREE_CODE (addr) == MEM_REF) 8221 attrs = TYPE_ATTRIBUTES (TREE_TYPE (TREE_OPERAND (addr, 0))); 8222 else 8223 return false; 8224 8225 if (lookup_attribute ("aux", attrs)) 8226 return true; 8227 return false; 8228 } 8229 8230 /* Implement ASM_OUTPUT_ALIGNED_DECL_LOCAL. */ 8231 8232 void 8233 arc_asm_output_aligned_decl_local (FILE * stream, tree decl, const char * name, 8234 unsigned HOST_WIDE_INT size, 8235 unsigned HOST_WIDE_INT align, 8236 unsigned HOST_WIDE_INT globalize_p) 8237 { 8238 int in_small_data = arc_in_small_data_p (decl); 8239 rtx mem = decl == NULL_TREE ? NULL_RTX : DECL_RTL (decl); 8240 8241 /* Don't output aux-reg symbols. */ 8242 if (mem != NULL_RTX && MEM_P (mem) 8243 && SYMBOL_REF_P (XEXP (mem, 0)) 8244 && arc_is_aux_reg_p (mem)) 8245 return; 8246 8247 if (in_small_data) 8248 switch_to_section (get_named_section (NULL, ".sbss", 0)); 8249 /* named_section (0,".sbss",0); */ 8250 else 8251 switch_to_section (bss_section); 8252 8253 if (globalize_p) 8254 (*targetm.asm_out.globalize_label) (stream, name); 8255 8256 ASM_OUTPUT_ALIGN (stream, floor_log2 ((align) / BITS_PER_UNIT)); 8257 ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "object"); 8258 ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size); 8259 ASM_OUTPUT_LABEL (stream, name); 8260 8261 if (size != 0) 8262 ASM_OUTPUT_SKIP (stream, size); 8263 } 8264 8265 static bool 8266 arc_preserve_reload_p (rtx in) 8267 { 8268 return (GET_CODE (in) == PLUS 8269 && RTX_OK_FOR_BASE_P (XEXP (in, 0), true) 8270 && CONST_INT_P (XEXP (in, 1)) 8271 && !((INTVAL (XEXP (in, 1)) & 511))); 8272 } 8273 8274 int 8275 arc_register_move_cost (machine_mode, 8276 enum reg_class from_class, enum reg_class to_class) 8277 { 8278 /* The ARC600 has no bypass for extension registers, hence a nop might be 8279 needed to be inserted after a write so that reads are safe. */ 8280 if (TARGET_ARC600) 8281 { 8282 if (to_class == MPY_WRITABLE_CORE_REGS) 8283 return 3; 8284 /* Instructions modifying LP_COUNT need 4 additional cycles before 8285 the register will actually contain the value. */ 8286 else if (to_class == LPCOUNT_REG) 8287 return 6; 8288 else if (to_class == WRITABLE_CORE_REGS) 8289 return 6; 8290 } 8291 8292 /* Using lp_count as scratch reg is a VERY bad idea. */ 8293 if (from_class == LPCOUNT_REG) 8294 return 1000; 8295 if (to_class == LPCOUNT_REG) 8296 return 6; 8297 8298 /* Force an attempt to 'mov Dy,Dx' to spill. */ 8299 if ((TARGET_ARC700 || TARGET_EM) && TARGET_DPFP 8300 && from_class == DOUBLE_REGS && to_class == DOUBLE_REGS) 8301 return 100; 8302 8303 return 2; 8304 } 8305 8306 /* Emit code for an addsi3 instruction with OPERANDS. 8307 COND_P indicates if this will use conditional execution. 8308 Return the length of the instruction. 8309 If OUTPUT_P is false, don't actually output the instruction, just return 8310 its length. */ 8311 int 8312 arc_output_addsi (rtx *operands, bool cond_p, bool output_p) 8313 { 8314 char format[35]; 8315 8316 int match = operands_match_p (operands[0], operands[1]); 8317 int match2 = operands_match_p (operands[0], operands[2]); 8318 int intval = (REG_P (operands[2]) ? 1 8319 : CONST_INT_P (operands[2]) ? INTVAL (operands[2]) : 0xbadc057); 8320 int neg_intval = -intval; 8321 int short_0 = satisfies_constraint_Rcq (operands[0]); 8322 int short_p = (!cond_p && short_0 && satisfies_constraint_Rcq (operands[1])); 8323 int ret = 0; 8324 8325 #define REG_H_P(OP) (REG_P (OP) && ((TARGET_V2 && REGNO (OP) <= 31 \ 8326 && REGNO (OP) != 30) \ 8327 || !TARGET_V2)) 8328 8329 #define ADDSI_OUTPUT1(FORMAT) do {\ 8330 if (output_p) \ 8331 output_asm_insn (FORMAT, operands);\ 8332 return ret; \ 8333 } while (0) 8334 #define ADDSI_OUTPUT(LIST) do {\ 8335 if (output_p) \ 8336 sprintf LIST;\ 8337 ADDSI_OUTPUT1 (format);\ 8338 return ret; \ 8339 } while (0) 8340 8341 /* First try to emit a 16 bit insn. */ 8342 ret = 2; 8343 if (!cond_p 8344 /* If we are actually about to output this insn, don't try a 16 bit 8345 variant if we already decided that we don't want that 8346 (I.e. we upsized this insn to align some following insn.) 8347 E.g. add_s r0,sp,70 is 16 bit, but add r0,sp,70 requires a LIMM - 8348 but add1 r0,sp,35 doesn't. */ 8349 && (!output_p || (get_attr_length (current_output_insn) & 2))) 8350 { 8351 /* Generate add_s a,b,c; add_s b,b,u7; add_s c,b,u3; add_s b,b,h 8352 patterns. */ 8353 if (short_p 8354 && ((REG_H_P (operands[2]) 8355 && (match || satisfies_constraint_Rcq (operands[2]))) 8356 || (CONST_INT_P (operands[2]) 8357 && ((unsigned) intval <= (match ? 127 : 7))))) 8358 ADDSI_OUTPUT1 ("add%? %0,%1,%2 ;1"); 8359 8360 /* Generate add_s b,b,h patterns. */ 8361 if (short_0 && match2 && REG_H_P (operands[1])) 8362 ADDSI_OUTPUT1 ("add%? %0,%2,%1 ;2"); 8363 8364 /* Generate add_s b,sp,u7; add_s sp,sp,u7 patterns. */ 8365 if ((short_0 || REGNO (operands[0]) == STACK_POINTER_REGNUM) 8366 && REGNO (operands[1]) == STACK_POINTER_REGNUM && !(intval & ~124)) 8367 ADDSI_OUTPUT1 ("add%? %0,%1,%2 ;3"); 8368 8369 if ((short_p && (unsigned) neg_intval <= (match ? 31 : 7)) 8370 || (REGNO (operands[0]) == STACK_POINTER_REGNUM 8371 && match && !(neg_intval & ~124))) 8372 ADDSI_OUTPUT1 ("sub%? %0,%1,%n2 ;4"); 8373 8374 /* Generate add_s h,h,s3 patterns. */ 8375 if (REG_H_P (operands[0]) && match && TARGET_V2 8376 && CONST_INT_P (operands[2]) && ((intval>= -1) && (intval <= 6))) 8377 ADDSI_OUTPUT1 ("add%? %0,%1,%2 ;5"); 8378 8379 /* Generate add_s r0,b,u6; add_s r1,b,u6 patterns. */ 8380 if (TARGET_CODE_DENSITY && REG_P (operands[0]) && REG_P (operands[1]) 8381 && ((REGNO (operands[0]) == 0) || (REGNO (operands[0]) == 1)) 8382 && satisfies_constraint_Rcq (operands[1]) 8383 && satisfies_constraint_L (operands[2])) 8384 ADDSI_OUTPUT1 ("add%? %0,%1,%2 ;6"); 8385 } 8386 8387 /* Now try to emit a 32 bit insn without long immediate. */ 8388 ret = 4; 8389 if (!match && match2 && REG_P (operands[1])) 8390 ADDSI_OUTPUT1 ("add%? %0,%2,%1"); 8391 if (match || !cond_p) 8392 { 8393 int limit = (match && !cond_p) ? 0x7ff : 0x3f; 8394 int range_factor = neg_intval & intval; 8395 int shift; 8396 8397 if (intval == (HOST_WIDE_INT) (HOST_WIDE_INT_M1U << 31)) 8398 ADDSI_OUTPUT1 ("bxor%? %0,%1,31"); 8399 8400 /* If we can use a straight add / sub instead of a {add,sub}[123] of 8401 same size, do, so - the insn latency is lower. */ 8402 /* -0x800 is a 12-bit constant for add /add3 / sub / sub3, but 8403 0x800 is not. */ 8404 if ((intval >= 0 && intval <= limit) 8405 || (intval == -0x800 && limit == 0x7ff)) 8406 ADDSI_OUTPUT1 ("add%? %0,%1,%2"); 8407 else if ((intval < 0 && neg_intval <= limit) 8408 || (intval == 0x800 && limit == 0x7ff)) 8409 ADDSI_OUTPUT1 ("sub%? %0,%1,%n2"); 8410 shift = range_factor >= 8 ? 3 : (range_factor >> 1); 8411 gcc_assert (shift == 0 || shift == 1 || shift == 2 || shift == 3); 8412 gcc_assert ((((1 << shift) - 1) & intval) == 0); 8413 if (((intval < 0 && intval != -0x4000) 8414 /* sub[123] is slower than add_s / sub, only use it if it 8415 avoids a long immediate. */ 8416 && neg_intval <= limit << shift) 8417 || (intval == 0x4000 && limit == 0x7ff)) 8418 ADDSI_OUTPUT ((format, "sub%d%%? %%0,%%1,%d", 8419 shift, neg_intval >> shift)); 8420 else if ((intval >= 0 && intval <= limit << shift) 8421 || (intval == -0x4000 && limit == 0x7ff)) 8422 ADDSI_OUTPUT ((format, "add%d%%? %%0,%%1,%d", shift, intval >> shift)); 8423 } 8424 /* Try to emit a 16 bit opcode with long immediate. */ 8425 ret = 6; 8426 if (short_p && match) 8427 ADDSI_OUTPUT1 ("add%? %0,%1,%2"); 8428 8429 /* We have to use a 32 bit opcode, and with a long immediate. */ 8430 ret = 8; 8431 ADDSI_OUTPUT1 (intval < 0 ? "sub%? %0,%1,%n2" : "add%? %0,%1,%2"); 8432 } 8433 8434 /* Emit code for an commutative_cond_exec instruction with OPERANDS. 8435 Return the length of the instruction. 8436 If OUTPUT_P is false, don't actually output the instruction, just return 8437 its length. */ 8438 int 8439 arc_output_commutative_cond_exec (rtx *operands, bool output_p) 8440 { 8441 enum rtx_code commutative_op = GET_CODE (operands[3]); 8442 const char *pat = NULL; 8443 8444 /* Canonical rtl should not have a constant in the first operand position. */ 8445 gcc_assert (!CONSTANT_P (operands[1])); 8446 8447 switch (commutative_op) 8448 { 8449 case AND: 8450 if (satisfies_constraint_C1p (operands[2])) 8451 pat = "bmsk%? %0,%1,%Z2"; 8452 else if (satisfies_constraint_C2p (operands[2])) 8453 { 8454 operands[2] = GEN_INT ((~INTVAL (operands[2]))); 8455 pat = "bmskn%? %0,%1,%Z2"; 8456 } 8457 else if (satisfies_constraint_Ccp (operands[2])) 8458 pat = "bclr%? %0,%1,%M2"; 8459 else if (satisfies_constraint_CnL (operands[2])) 8460 pat = "bic%? %0,%1,%n2-1"; 8461 break; 8462 case IOR: 8463 if (satisfies_constraint_C0p (operands[2])) 8464 pat = "bset%? %0,%1,%z2"; 8465 break; 8466 case XOR: 8467 if (satisfies_constraint_C0p (operands[2])) 8468 pat = "bxor%? %0,%1,%z2"; 8469 break; 8470 case PLUS: 8471 return arc_output_addsi (operands, true, output_p); 8472 default: break; 8473 } 8474 if (output_p) 8475 output_asm_insn (pat ? pat : "%O3.%d5 %0,%1,%2", operands); 8476 if (pat || REG_P (operands[2]) || satisfies_constraint_L (operands[2])) 8477 return 4; 8478 return 8; 8479 } 8480 8481 /* Helper function of arc_expand_movmem. ADDR points to a chunk of memory. 8482 Emit code and return an potentially modified address such that offsets 8483 up to SIZE are can be added to yield a legitimate address. 8484 if REUSE is set, ADDR is a register that may be modified. */ 8485 8486 static rtx 8487 force_offsettable (rtx addr, HOST_WIDE_INT size, bool reuse) 8488 { 8489 rtx base = addr; 8490 rtx offs = const0_rtx; 8491 8492 if (GET_CODE (base) == PLUS) 8493 { 8494 offs = XEXP (base, 1); 8495 base = XEXP (base, 0); 8496 } 8497 if (!REG_P (base) 8498 || (REGNO (base) != STACK_POINTER_REGNUM 8499 && REGNO_PTR_FRAME_P (REGNO (base))) 8500 || !CONST_INT_P (offs) || !SMALL_INT (INTVAL (offs)) 8501 || !SMALL_INT (INTVAL (offs) + size)) 8502 { 8503 if (reuse) 8504 emit_insn (gen_add2_insn (addr, offs)); 8505 else 8506 addr = copy_to_mode_reg (Pmode, addr); 8507 } 8508 return addr; 8509 } 8510 8511 /* Like move_by_pieces, but take account of load latency, and actual 8512 offset ranges. Return true on success. */ 8513 8514 bool 8515 arc_expand_movmem (rtx *operands) 8516 { 8517 rtx dst = operands[0]; 8518 rtx src = operands[1]; 8519 rtx dst_addr, src_addr; 8520 HOST_WIDE_INT size; 8521 int align = INTVAL (operands[3]); 8522 unsigned n_pieces; 8523 int piece = align; 8524 rtx store[2]; 8525 rtx tmpx[2]; 8526 int i; 8527 8528 if (!CONST_INT_P (operands[2])) 8529 return false; 8530 size = INTVAL (operands[2]); 8531 /* move_by_pieces_ninsns is static, so we can't use it. */ 8532 if (align >= 4) 8533 { 8534 if (TARGET_LL64) 8535 n_pieces = (size + 4) / 8U + ((size >> 1) & 1) + (size & 1); 8536 else 8537 n_pieces = (size + 2) / 4U + (size & 1); 8538 } 8539 else if (align == 2) 8540 n_pieces = (size + 1) / 2U; 8541 else 8542 n_pieces = size; 8543 if (n_pieces >= (unsigned int) (optimize_size ? 3 : 15)) 8544 return false; 8545 /* Force 32 bit aligned and larger datum to use 64 bit transfers, if 8546 possible. */ 8547 if (TARGET_LL64 && (piece >= 4) && (size >= 8)) 8548 piece = 8; 8549 else if (piece > 4) 8550 piece = 4; 8551 dst_addr = force_offsettable (XEXP (operands[0], 0), size, 0); 8552 src_addr = force_offsettable (XEXP (operands[1], 0), size, 0); 8553 store[0] = store[1] = NULL_RTX; 8554 tmpx[0] = tmpx[1] = NULL_RTX; 8555 for (i = 0; size > 0; i ^= 1, size -= piece) 8556 { 8557 rtx tmp; 8558 machine_mode mode; 8559 8560 while (piece > size) 8561 piece >>= 1; 8562 mode = smallest_int_mode_for_size (piece * BITS_PER_UNIT); 8563 /* If we don't re-use temporaries, the scheduler gets carried away, 8564 and the register pressure gets unnecessarily high. */ 8565 if (0 && tmpx[i] && GET_MODE (tmpx[i]) == mode) 8566 tmp = tmpx[i]; 8567 else 8568 tmpx[i] = tmp = gen_reg_rtx (mode); 8569 dst_addr = force_offsettable (dst_addr, piece, 1); 8570 src_addr = force_offsettable (src_addr, piece, 1); 8571 if (store[i]) 8572 emit_insn (store[i]); 8573 emit_move_insn (tmp, change_address (src, mode, src_addr)); 8574 store[i] = gen_move_insn (change_address (dst, mode, dst_addr), tmp); 8575 dst_addr = plus_constant (Pmode, dst_addr, piece); 8576 src_addr = plus_constant (Pmode, src_addr, piece); 8577 } 8578 if (store[i]) 8579 emit_insn (store[i]); 8580 if (store[i^1]) 8581 emit_insn (store[i^1]); 8582 return true; 8583 } 8584 8585 static bool 8586 arc_get_aux_arg (rtx pat, int *auxr) 8587 { 8588 tree attr, addr = MEM_EXPR (pat); 8589 if (TREE_CODE (addr) != VAR_DECL) 8590 return false; 8591 8592 attr = DECL_ATTRIBUTES (addr); 8593 if (lookup_attribute ("aux", attr)) 8594 { 8595 tree arg = TREE_VALUE (attr); 8596 if (arg) 8597 { 8598 *auxr = TREE_INT_CST_LOW (TREE_VALUE (arg)); 8599 return true; 8600 } 8601 } 8602 8603 return false; 8604 } 8605 8606 /* Prepare operands for move in MODE. Return true iff the move has 8607 been emitted. */ 8608 8609 bool 8610 prepare_move_operands (rtx *operands, machine_mode mode) 8611 { 8612 /* First handle aux attribute. */ 8613 if (mode == SImode 8614 && (MEM_P (operands[0]) || MEM_P (operands[1]))) 8615 { 8616 rtx tmp; 8617 int auxr = 0; 8618 if (MEM_P (operands[0]) && arc_is_aux_reg_p (operands[0])) 8619 { 8620 /* Save operation. */ 8621 if (arc_get_aux_arg (operands[0], &auxr)) 8622 { 8623 tmp = gen_reg_rtx (SImode); 8624 emit_move_insn (tmp, GEN_INT (auxr)); 8625 } 8626 else 8627 { 8628 tmp = XEXP (operands[0], 0); 8629 } 8630 8631 operands[1] = force_reg (SImode, operands[1]); 8632 emit_insn (gen_rtx_UNSPEC_VOLATILE 8633 (VOIDmode, gen_rtvec (2, operands[1], tmp), 8634 VUNSPEC_ARC_SR)); 8635 return true; 8636 } 8637 if (MEM_P (operands[1]) && arc_is_aux_reg_p (operands[1])) 8638 { 8639 if (arc_get_aux_arg (operands[1], &auxr)) 8640 { 8641 tmp = gen_reg_rtx (SImode); 8642 emit_move_insn (tmp, GEN_INT (auxr)); 8643 } 8644 else 8645 { 8646 tmp = XEXP (operands[1], 0); 8647 gcc_assert (GET_CODE (tmp) == SYMBOL_REF); 8648 } 8649 /* Load operation. */ 8650 gcc_assert (REG_P (operands[0])); 8651 emit_insn (gen_rtx_SET (operands[0], 8652 gen_rtx_UNSPEC_VOLATILE 8653 (SImode, gen_rtvec (1, tmp), 8654 VUNSPEC_ARC_LR))); 8655 return true; 8656 } 8657 } 8658 8659 /* We used to do this only for MODE_INT Modes, but addresses to floating 8660 point variables may well be in the small data section. */ 8661 if (!TARGET_NO_SDATA_SET && small_data_pattern (operands[0], Pmode)) 8662 operands[0] = arc_rewrite_small_data (operands[0]); 8663 8664 if (mode == SImode && SYMBOLIC_CONST (operands[1])) 8665 { 8666 prepare_pic_move (operands, SImode); 8667 8668 /* Disable any REG_EQUALs associated with the symref 8669 otherwise the optimization pass undoes the work done 8670 here and references the variable directly. */ 8671 } 8672 8673 if (GET_CODE (operands[0]) != MEM 8674 && !TARGET_NO_SDATA_SET 8675 && small_data_pattern (operands[1], Pmode)) 8676 { 8677 /* This is to take care of address calculations involving sdata 8678 variables. */ 8679 operands[1] = arc_rewrite_small_data (operands[1]); 8680 8681 emit_insn (gen_rtx_SET (operands[0],operands[1])); 8682 /* ??? This note is useless, since it only restates the set itself. 8683 We should rather use the original SYMBOL_REF. However, there is 8684 the problem that we are lying to the compiler about these 8685 SYMBOL_REFs to start with. symbol@sda should be encoded specially 8686 so that we can tell it apart from an actual symbol. */ 8687 set_unique_reg_note (get_last_insn (), REG_EQUAL, operands[1]); 8688 8689 /* Take care of the REG_EQUAL note that will be attached to mark the 8690 output reg equal to the initial symbol_ref after this code is 8691 executed. */ 8692 emit_move_insn (operands[0], operands[0]); 8693 return true; 8694 } 8695 8696 if (MEM_P (operands[0]) 8697 && !(reload_in_progress || reload_completed)) 8698 { 8699 operands[1] = force_reg (mode, operands[1]); 8700 if (!move_dest_operand (operands[0], mode)) 8701 { 8702 rtx addr = copy_to_mode_reg (Pmode, XEXP (operands[0], 0)); 8703 /* This is like change_address_1 (operands[0], mode, 0, 1) , 8704 except that we can't use that function because it is static. */ 8705 rtx pat = change_address (operands[0], mode, addr); 8706 MEM_COPY_ATTRIBUTES (pat, operands[0]); 8707 operands[0] = pat; 8708 } 8709 if (!cse_not_expected) 8710 { 8711 rtx pat = XEXP (operands[0], 0); 8712 8713 pat = arc_legitimize_address_0 (pat, pat, mode); 8714 if (pat) 8715 { 8716 pat = change_address (operands[0], mode, pat); 8717 MEM_COPY_ATTRIBUTES (pat, operands[0]); 8718 operands[0] = pat; 8719 } 8720 } 8721 } 8722 8723 if (MEM_P (operands[1]) && !cse_not_expected) 8724 { 8725 rtx pat = XEXP (operands[1], 0); 8726 8727 pat = arc_legitimize_address_0 (pat, pat, mode); 8728 if (pat) 8729 { 8730 pat = change_address (operands[1], mode, pat); 8731 MEM_COPY_ATTRIBUTES (pat, operands[1]); 8732 operands[1] = pat; 8733 } 8734 } 8735 8736 return false; 8737 } 8738 8739 /* Prepare OPERANDS for an extension using CODE to OMODE. 8740 Return true iff the move has been emitted. */ 8741 8742 bool 8743 prepare_extend_operands (rtx *operands, enum rtx_code code, 8744 machine_mode omode) 8745 { 8746 if (!TARGET_NO_SDATA_SET && small_data_pattern (operands[1], Pmode)) 8747 { 8748 /* This is to take care of address calculations involving sdata 8749 variables. */ 8750 operands[1] 8751 = gen_rtx_fmt_e (code, omode, arc_rewrite_small_data (operands[1])); 8752 emit_insn (gen_rtx_SET (operands[0], operands[1])); 8753 set_unique_reg_note (get_last_insn (), REG_EQUAL, operands[1]); 8754 8755 /* Take care of the REG_EQUAL note that will be attached to mark the 8756 output reg equal to the initial extension after this code is 8757 executed. */ 8758 emit_move_insn (operands[0], operands[0]); 8759 return true; 8760 } 8761 return false; 8762 } 8763 8764 /* Output a library call to a function called FNAME that has been arranged 8765 to be local to any dso. */ 8766 8767 const char * 8768 arc_output_libcall (const char *fname) 8769 { 8770 unsigned len = strlen (fname); 8771 static char buf[64]; 8772 8773 gcc_assert (len < sizeof buf - 35); 8774 if (TARGET_LONG_CALLS_SET 8775 || (TARGET_MEDIUM_CALLS && arc_ccfsm_cond_exec_p ())) 8776 { 8777 if (flag_pic) 8778 sprintf (buf, "add r12,pcl,@%s@pcl\n\tjl%%!%%* [r12]", fname); 8779 else 8780 sprintf (buf, "jl%%! @%s", fname); 8781 } 8782 else 8783 sprintf (buf, "bl%%!%%* @%s", fname); 8784 return buf; 8785 } 8786 8787 /* Return the SImode highpart of the DImode value IN. */ 8788 8789 rtx 8790 disi_highpart (rtx in) 8791 { 8792 return simplify_gen_subreg (SImode, in, DImode, TARGET_BIG_ENDIAN ? 0 : 4); 8793 } 8794 8795 /* Return length adjustment for INSN. 8796 For ARC600: 8797 A write to a core reg greater or equal to 32 must not be immediately 8798 followed by a use. Anticipate the length requirement to insert a nop 8799 between PRED and SUCC to prevent a hazard. */ 8800 8801 static int 8802 arc600_corereg_hazard (rtx_insn *pred, rtx_insn *succ) 8803 { 8804 if (!TARGET_ARC600) 8805 return 0; 8806 if (GET_CODE (PATTERN (pred)) == SEQUENCE) 8807 pred = as_a <rtx_sequence *> (PATTERN (pred))->insn (1); 8808 if (GET_CODE (PATTERN (succ)) == SEQUENCE) 8809 succ = as_a <rtx_sequence *> (PATTERN (succ))->insn (0); 8810 if (recog_memoized (pred) == CODE_FOR_mulsi_600 8811 || recog_memoized (pred) == CODE_FOR_umul_600 8812 || recog_memoized (pred) == CODE_FOR_mac_600 8813 || recog_memoized (pred) == CODE_FOR_mul64_600 8814 || recog_memoized (pred) == CODE_FOR_mac64_600 8815 || recog_memoized (pred) == CODE_FOR_umul64_600 8816 || recog_memoized (pred) == CODE_FOR_umac64_600) 8817 return 0; 8818 subrtx_iterator::array_type array; 8819 FOR_EACH_SUBRTX (iter, array, PATTERN (pred), NONCONST) 8820 { 8821 const_rtx x = *iter; 8822 switch (GET_CODE (x)) 8823 { 8824 case SET: case POST_INC: case POST_DEC: case PRE_INC: case PRE_DEC: 8825 break; 8826 default: 8827 /* This is also fine for PRE/POST_MODIFY, because they 8828 contain a SET. */ 8829 continue; 8830 } 8831 rtx dest = XEXP (x, 0); 8832 /* Check if this sets a an extension register. N.B. we use 61 for the 8833 condition codes, which is definitely not an extension register. */ 8834 if (REG_P (dest) && REGNO (dest) >= 32 && REGNO (dest) < 61 8835 /* Check if the same register is used by the PAT. */ 8836 && (refers_to_regno_p 8837 (REGNO (dest), 8838 REGNO (dest) + (GET_MODE_SIZE (GET_MODE (dest)) + 3) / 4U, 8839 PATTERN (succ), 0))) 8840 return 4; 8841 } 8842 return 0; 8843 } 8844 8845 /* Given a rtx, check if it is an assembly instruction or not. */ 8846 8847 static int 8848 arc_asm_insn_p (rtx x) 8849 { 8850 int i, j; 8851 8852 if (x == 0) 8853 return 0; 8854 8855 switch (GET_CODE (x)) 8856 { 8857 case ASM_OPERANDS: 8858 case ASM_INPUT: 8859 return 1; 8860 8861 case SET: 8862 return arc_asm_insn_p (SET_SRC (x)); 8863 8864 case PARALLEL: 8865 j = 0; 8866 for (i = XVECLEN (x, 0) - 1; i >= 0; i--) 8867 j += arc_asm_insn_p (XVECEXP (x, 0, i)); 8868 if ( j > 0) 8869 return 1; 8870 break; 8871 8872 default: 8873 break; 8874 } 8875 8876 return 0; 8877 } 8878 8879 /* For ARC600: 8880 A write to a core reg greater or equal to 32 must not be immediately 8881 followed by a use. Anticipate the length requirement to insert a nop 8882 between PRED and SUCC to prevent a hazard. */ 8883 8884 int 8885 arc_hazard (rtx_insn *pred, rtx_insn *succ) 8886 { 8887 if (!pred || !INSN_P (pred) || !succ || !INSN_P (succ)) 8888 return 0; 8889 8890 if (TARGET_ARC600) 8891 return arc600_corereg_hazard (pred, succ); 8892 8893 return 0; 8894 } 8895 8896 /* Return length adjustment for INSN. */ 8897 8898 int 8899 arc_adjust_insn_length (rtx_insn *insn, int len, bool) 8900 { 8901 if (!INSN_P (insn)) 8902 return len; 8903 /* We already handle sequences by ignoring the delay sequence flag. */ 8904 if (GET_CODE (PATTERN (insn)) == SEQUENCE) 8905 return len; 8906 8907 /* Check for return with but one preceding insn since function 8908 start / call. */ 8909 if (TARGET_PAD_RETURN 8910 && JUMP_P (insn) 8911 && GET_CODE (PATTERN (insn)) != ADDR_VEC 8912 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC 8913 && get_attr_type (insn) == TYPE_RETURN) 8914 { 8915 rtx_insn *prev = prev_active_insn (insn); 8916 8917 if (!prev || !(prev = prev_active_insn (prev)) 8918 || ((NONJUMP_INSN_P (prev) 8919 && GET_CODE (PATTERN (prev)) == SEQUENCE) 8920 ? CALL_ATTR (as_a <rtx_sequence *> (PATTERN (prev))->insn (0), 8921 NON_SIBCALL) 8922 : CALL_ATTR (prev, NON_SIBCALL))) 8923 return len + 4; 8924 } 8925 if (TARGET_ARC600) 8926 { 8927 rtx_insn *succ = next_real_insn (insn); 8928 8929 /* One the ARC600, a write to an extension register must be separated 8930 from a read. */ 8931 if (succ && INSN_P (succ)) 8932 len += arc600_corereg_hazard (insn, succ); 8933 } 8934 8935 /* Restore extracted operands - otherwise splitters like the addsi3_mixed one 8936 can go awry. */ 8937 extract_constrain_insn_cached (insn); 8938 8939 return len; 8940 } 8941 8942 /* Return a copy of COND from *STATEP, inverted if that is indicated by the 8943 CC field of *STATEP. */ 8944 8945 static rtx 8946 arc_get_ccfsm_cond (struct arc_ccfsm *statep, bool reverse) 8947 { 8948 rtx cond = statep->cond; 8949 int raw_cc = get_arc_condition_code (cond); 8950 if (reverse) 8951 raw_cc = ARC_INVERSE_CONDITION_CODE (raw_cc); 8952 8953 if (statep->cc == raw_cc) 8954 return copy_rtx (cond); 8955 8956 gcc_assert (ARC_INVERSE_CONDITION_CODE (raw_cc) == statep->cc); 8957 8958 machine_mode ccm = GET_MODE (XEXP (cond, 0)); 8959 enum rtx_code code = reverse_condition (GET_CODE (cond)); 8960 if (code == UNKNOWN || ccm == CC_FP_GTmode || ccm == CC_FP_GEmode) 8961 code = reverse_condition_maybe_unordered (GET_CODE (cond)); 8962 8963 return gen_rtx_fmt_ee (code, GET_MODE (cond), 8964 copy_rtx (XEXP (cond, 0)), copy_rtx (XEXP (cond, 1))); 8965 } 8966 8967 /* Return version of PAT conditionalized with COND, which is part of INSN. 8968 ANNULLED indicates if INSN is an annulled delay-slot insn. 8969 Register further changes if necessary. */ 8970 static rtx 8971 conditionalize_nonjump (rtx pat, rtx cond, rtx insn, bool annulled) 8972 { 8973 /* For commutative operators, we generally prefer to have 8974 the first source match the destination. */ 8975 if (GET_CODE (pat) == SET) 8976 { 8977 rtx src = SET_SRC (pat); 8978 8979 if (COMMUTATIVE_P (src)) 8980 { 8981 rtx src0 = XEXP (src, 0); 8982 rtx src1 = XEXP (src, 1); 8983 rtx dst = SET_DEST (pat); 8984 8985 if (rtx_equal_p (src1, dst) && !rtx_equal_p (src0, dst) 8986 /* Leave add_n alone - the canonical form is to 8987 have the complex summand first. */ 8988 && REG_P (src0)) 8989 pat = gen_rtx_SET (dst, 8990 gen_rtx_fmt_ee (GET_CODE (src), GET_MODE (src), 8991 src1, src0)); 8992 } 8993 } 8994 8995 /* dwarf2out.c:dwarf2out_frame_debug_expr doesn't know 8996 what to do with COND_EXEC. */ 8997 if (RTX_FRAME_RELATED_P (insn)) 8998 { 8999 /* If this is the delay slot insn of an anulled branch, 9000 dwarf2out.c:scan_trace understands the anulling semantics 9001 without the COND_EXEC. */ 9002 gcc_assert (annulled); 9003 rtx note = alloc_reg_note (REG_FRAME_RELATED_EXPR, pat, 9004 REG_NOTES (insn)); 9005 validate_change (insn, ®_NOTES (insn), note, 1); 9006 } 9007 pat = gen_rtx_COND_EXEC (VOIDmode, cond, pat); 9008 return pat; 9009 } 9010 9011 /* Use the ccfsm machinery to do if conversion. */ 9012 9013 static unsigned 9014 arc_ifcvt (void) 9015 { 9016 struct arc_ccfsm *statep = &cfun->machine->ccfsm_current; 9017 9018 memset (statep, 0, sizeof *statep); 9019 for (rtx_insn *insn = get_insns (); insn; insn = next_insn (insn)) 9020 { 9021 arc_ccfsm_advance (insn, statep); 9022 9023 switch (statep->state) 9024 { 9025 case 0: 9026 break; 9027 case 1: case 2: 9028 { 9029 /* Deleted branch. */ 9030 arc_ccfsm_post_advance (insn, statep); 9031 gcc_assert (!IN_RANGE (statep->state, 1, 2)); 9032 rtx_insn *seq = NEXT_INSN (PREV_INSN (insn)); 9033 if (GET_CODE (PATTERN (seq)) == SEQUENCE) 9034 { 9035 rtx slot = XVECEXP (PATTERN (seq), 0, 1); 9036 rtx pat = PATTERN (slot); 9037 if (INSN_ANNULLED_BRANCH_P (insn)) 9038 { 9039 rtx cond 9040 = arc_get_ccfsm_cond (statep, INSN_FROM_TARGET_P (slot)); 9041 pat = gen_rtx_COND_EXEC (VOIDmode, cond, pat); 9042 } 9043 if (!validate_change (seq, &PATTERN (seq), pat, 0)) 9044 gcc_unreachable (); 9045 PUT_CODE (slot, NOTE); 9046 NOTE_KIND (slot) = NOTE_INSN_DELETED; 9047 } 9048 else 9049 { 9050 set_insn_deleted (insn); 9051 } 9052 continue; 9053 } 9054 case 3: 9055 if (LABEL_P (insn) 9056 && statep->target_label == CODE_LABEL_NUMBER (insn)) 9057 { 9058 arc_ccfsm_post_advance (insn, statep); 9059 if (--LABEL_NUSES (insn) == 0) 9060 delete_insn (insn); 9061 continue; 9062 } 9063 /* Fall through. */ 9064 case 4: case 5: 9065 if (!NONDEBUG_INSN_P (insn)) 9066 break; 9067 9068 /* Conditionalized insn. */ 9069 9070 rtx_insn *prev, *pprev; 9071 rtx *patp, pat, cond; 9072 bool annulled; annulled = false; 9073 9074 /* If this is a delay slot insn in a non-annulled branch, 9075 don't conditionalize it. N.B., this should be fine for 9076 conditional return too. However, don't do this for 9077 unconditional branches, as these would be encountered when 9078 processing an 'else' part. */ 9079 prev = PREV_INSN (insn); 9080 pprev = PREV_INSN (prev); 9081 if (pprev && NEXT_INSN (NEXT_INSN (pprev)) == NEXT_INSN (insn) 9082 && JUMP_P (prev) && get_attr_cond (prev) == COND_USE) 9083 { 9084 if (!INSN_ANNULLED_BRANCH_P (prev)) 9085 break; 9086 annulled = true; 9087 } 9088 9089 patp = &PATTERN (insn); 9090 pat = *patp; 9091 cond = arc_get_ccfsm_cond (statep, INSN_FROM_TARGET_P (insn)); 9092 if (NONJUMP_INSN_P (insn) || CALL_P (insn)) 9093 { 9094 /* ??? don't conditionalize if all side effects are dead 9095 in the not-execute case. */ 9096 9097 pat = conditionalize_nonjump (pat, cond, insn, annulled); 9098 } 9099 else if (simplejump_p (insn)) 9100 { 9101 patp = &SET_SRC (pat); 9102 pat = gen_rtx_IF_THEN_ELSE (VOIDmode, cond, *patp, pc_rtx); 9103 } 9104 else if (JUMP_P (insn) && ANY_RETURN_P (PATTERN (insn))) 9105 { 9106 pat = gen_rtx_IF_THEN_ELSE (VOIDmode, cond, pat, pc_rtx); 9107 pat = gen_rtx_SET (pc_rtx, pat); 9108 } 9109 else 9110 gcc_unreachable (); 9111 validate_change (insn, patp, pat, 1); 9112 if (!apply_change_group ()) 9113 gcc_unreachable (); 9114 if (JUMP_P (insn)) 9115 { 9116 rtx_insn *next = next_nonnote_insn (insn); 9117 if (GET_CODE (next) == BARRIER) 9118 delete_insn (next); 9119 if (statep->state == 3) 9120 continue; 9121 } 9122 break; 9123 default: 9124 gcc_unreachable (); 9125 } 9126 arc_ccfsm_post_advance (insn, statep); 9127 } 9128 return 0; 9129 } 9130 9131 /* Find annulled delay insns and convert them to use the appropriate predicate. 9132 This allows branch shortening to size up these insns properly. */ 9133 9134 static unsigned 9135 arc_predicate_delay_insns (void) 9136 { 9137 for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn)) 9138 { 9139 rtx pat, jump, dlay, src, cond, *patp; 9140 int reverse; 9141 9142 if (!NONJUMP_INSN_P (insn) 9143 || GET_CODE (pat = PATTERN (insn)) != SEQUENCE) 9144 continue; 9145 jump = XVECEXP (pat, 0, 0); 9146 dlay = XVECEXP (pat, 0, 1); 9147 if (!JUMP_P (jump) || !INSN_ANNULLED_BRANCH_P (jump)) 9148 continue; 9149 /* If the branch insn does the annulling, leave the delay insn alone. */ 9150 if (!TARGET_AT_DBR_CONDEXEC && !INSN_FROM_TARGET_P (dlay)) 9151 continue; 9152 /* ??? Could also leave DLAY un-conditionalized if its target is dead 9153 on the other path. */ 9154 gcc_assert (GET_CODE (PATTERN (jump)) == SET); 9155 gcc_assert (SET_DEST (PATTERN (jump)) == pc_rtx); 9156 src = SET_SRC (PATTERN (jump)); 9157 gcc_assert (GET_CODE (src) == IF_THEN_ELSE); 9158 cond = XEXP (src, 0); 9159 if (XEXP (src, 2) == pc_rtx) 9160 reverse = 0; 9161 else if (XEXP (src, 1) == pc_rtx) 9162 reverse = 1; 9163 else 9164 gcc_unreachable (); 9165 if (reverse != !INSN_FROM_TARGET_P (dlay)) 9166 { 9167 machine_mode ccm = GET_MODE (XEXP (cond, 0)); 9168 enum rtx_code code = reverse_condition (GET_CODE (cond)); 9169 if (code == UNKNOWN || ccm == CC_FP_GTmode || ccm == CC_FP_GEmode) 9170 code = reverse_condition_maybe_unordered (GET_CODE (cond)); 9171 9172 cond = gen_rtx_fmt_ee (code, GET_MODE (cond), 9173 copy_rtx (XEXP (cond, 0)), 9174 copy_rtx (XEXP (cond, 1))); 9175 } 9176 else 9177 cond = copy_rtx (cond); 9178 patp = &PATTERN (dlay); 9179 pat = *patp; 9180 pat = conditionalize_nonjump (pat, cond, dlay, true); 9181 validate_change (dlay, patp, pat, 1); 9182 if (!apply_change_group ()) 9183 gcc_unreachable (); 9184 } 9185 return 0; 9186 } 9187 9188 /* For ARC600: If a write to a core reg >=32 appears in a delay slot 9189 (other than of a forward brcc), it creates a hazard when there is a read 9190 of the same register at the branch target. We can't know what is at the 9191 branch target of calls, and for branches, we don't really know before the 9192 end of delay slot scheduling, either. Not only can individual instruction 9193 be hoisted out into a delay slot, a basic block can also be emptied this 9194 way, and branch and/or fall through targets be redirected. Hence we don't 9195 want such writes in a delay slot. */ 9196 9197 /* Return nonzreo iff INSN writes to an extension core register. */ 9198 9199 int 9200 arc_write_ext_corereg (rtx insn) 9201 { 9202 subrtx_iterator::array_type array; 9203 FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST) 9204 { 9205 const_rtx x = *iter; 9206 switch (GET_CODE (x)) 9207 { 9208 case SET: case POST_INC: case POST_DEC: case PRE_INC: case PRE_DEC: 9209 break; 9210 default: 9211 /* This is also fine for PRE/POST_MODIFY, because they 9212 contain a SET. */ 9213 continue; 9214 } 9215 const_rtx dest = XEXP (x, 0); 9216 if (REG_P (dest) && REGNO (dest) >= 32 && REGNO (dest) < 61) 9217 return 1; 9218 } 9219 return 0; 9220 } 9221 9222 /* This is like the hook, but returns NULL when it can't / won't generate 9223 a legitimate address. */ 9224 9225 static rtx 9226 arc_legitimize_address_0 (rtx x, rtx oldx ATTRIBUTE_UNUSED, 9227 machine_mode mode) 9228 { 9229 rtx addr, inner; 9230 9231 if (flag_pic && SYMBOLIC_CONST (x)) 9232 (x) = arc_legitimize_pic_address (x, 0); 9233 addr = x; 9234 if (GET_CODE (addr) == CONST) 9235 addr = XEXP (addr, 0); 9236 if (GET_CODE (addr) == PLUS 9237 && CONST_INT_P (XEXP (addr, 1)) 9238 && ((GET_CODE (XEXP (addr, 0)) == SYMBOL_REF 9239 && !SYMBOL_REF_FUNCTION_P (XEXP (addr, 0))) 9240 || (REG_P (XEXP (addr, 0)) 9241 && (INTVAL (XEXP (addr, 1)) & 252)))) 9242 { 9243 HOST_WIDE_INT offs, upper; 9244 int size = GET_MODE_SIZE (mode); 9245 9246 offs = INTVAL (XEXP (addr, 1)); 9247 upper = (offs + 256 * size) & ~511 * size; 9248 inner = plus_constant (Pmode, XEXP (addr, 0), upper); 9249 #if 0 /* ??? this produces worse code for EEMBC idctrn01 */ 9250 if (GET_CODE (x) == CONST) 9251 inner = gen_rtx_CONST (Pmode, inner); 9252 #endif 9253 addr = plus_constant (Pmode, force_reg (Pmode, inner), offs - upper); 9254 x = addr; 9255 } 9256 else if (GET_CODE (addr) == SYMBOL_REF && !SYMBOL_REF_FUNCTION_P (addr)) 9257 x = force_reg (Pmode, x); 9258 if (memory_address_p ((machine_mode) mode, x)) 9259 return x; 9260 return NULL_RTX; 9261 } 9262 9263 static rtx 9264 arc_legitimize_address (rtx orig_x, rtx oldx, machine_mode mode) 9265 { 9266 if (GET_CODE (orig_x) == SYMBOL_REF) 9267 { 9268 enum tls_model model = SYMBOL_REF_TLS_MODEL (orig_x); 9269 if (model != 0) 9270 return arc_legitimize_tls_address (orig_x, model); 9271 } 9272 9273 rtx new_x = arc_legitimize_address_0 (orig_x, oldx, mode); 9274 9275 if (new_x) 9276 return new_x; 9277 return orig_x; 9278 } 9279 9280 static rtx 9281 arc_delegitimize_address_0 (rtx op) 9282 { 9283 switch (GET_CODE (op)) 9284 { 9285 case CONST: 9286 return arc_delegitimize_address_0 (XEXP (op, 0)); 9287 9288 case UNSPEC: 9289 switch (XINT (op, 1)) 9290 { 9291 case ARC_UNSPEC_GOT: 9292 case ARC_UNSPEC_GOTOFFPC: 9293 return XVECEXP (op, 0, 0); 9294 default: 9295 break; 9296 } 9297 break; 9298 9299 case PLUS: 9300 { 9301 rtx t1 = arc_delegitimize_address_0 (XEXP (op, 0)); 9302 rtx t2 = XEXP (op, 1); 9303 9304 if (t1 && t2) 9305 return gen_rtx_PLUS (GET_MODE (op), t1, t2); 9306 break; 9307 } 9308 9309 default: 9310 break; 9311 } 9312 return NULL_RTX; 9313 } 9314 9315 static rtx 9316 arc_delegitimize_address (rtx orig_x) 9317 { 9318 rtx x = orig_x; 9319 9320 if (MEM_P (x)) 9321 x = XEXP (x, 0); 9322 9323 x = arc_delegitimize_address_0 (x); 9324 if (!x) 9325 return orig_x; 9326 9327 if (MEM_P (orig_x)) 9328 x = replace_equiv_address_nv (orig_x, x); 9329 return x; 9330 } 9331 9332 /* Return a REG rtx for acc1. N.B. the gcc-internal representation may 9333 differ from the hardware register number in order to allow the generic 9334 code to correctly split the concatenation of acc1 and acc2. */ 9335 9336 rtx 9337 gen_acc1 (void) 9338 { 9339 return gen_rtx_REG (SImode, TARGET_BIG_ENDIAN ? 56: 57); 9340 } 9341 9342 /* Return a REG rtx for acc2. N.B. the gcc-internal representation may 9343 differ from the hardware register number in order to allow the generic 9344 code to correctly split the concatenation of acc1 and acc2. */ 9345 9346 rtx 9347 gen_acc2 (void) 9348 { 9349 return gen_rtx_REG (SImode, TARGET_BIG_ENDIAN ? 57: 56); 9350 } 9351 9352 /* Return a REG rtx for mlo. N.B. the gcc-internal representation may 9353 differ from the hardware register number in order to allow the generic 9354 code to correctly split the concatenation of mhi and mlo. */ 9355 9356 rtx 9357 gen_mlo (void) 9358 { 9359 return gen_rtx_REG (SImode, TARGET_BIG_ENDIAN ? 59: 58); 9360 } 9361 9362 /* Return a REG rtx for mhi. N.B. the gcc-internal representation may 9363 differ from the hardware register number in order to allow the generic 9364 code to correctly split the concatenation of mhi and mlo. */ 9365 9366 rtx 9367 gen_mhi (void) 9368 { 9369 return gen_rtx_REG (SImode, TARGET_BIG_ENDIAN ? 58: 59); 9370 } 9371 9372 /* FIXME: a parameter should be added, and code added to final.c, 9373 to reproduce this functionality in shorten_branches. */ 9374 #if 0 9375 /* Return nonzero iff BRANCH should be unaligned if possible by upsizing 9376 a previous instruction. */ 9377 int 9378 arc_unalign_branch_p (rtx branch) 9379 { 9380 rtx note; 9381 9382 if (!TARGET_UNALIGN_BRANCH) 9383 return 0; 9384 /* Do not do this if we have a filled delay slot. */ 9385 if (get_attr_delay_slot_filled (branch) == DELAY_SLOT_FILLED_YES 9386 && !NEXT_INSN (branch)->deleted ()) 9387 return 0; 9388 note = find_reg_note (branch, REG_BR_PROB, 0); 9389 return (!note 9390 || (arc_unalign_prob_threshold && !br_prob_note_reliable_p (note)) 9391 || INTVAL (XEXP (note, 0)) < arc_unalign_prob_threshold); 9392 } 9393 #endif 9394 9395 /* When estimating sizes during arc_reorg, when optimizing for speed, there 9396 are three reasons why we need to consider branches to be length 6: 9397 - annull-false delay slot insns are implemented using conditional execution, 9398 thus preventing short insn formation where used. 9399 - for ARC600: annul-true delay slot insns are implemented where possible 9400 using conditional execution, preventing short insn formation where used. 9401 - for ARC700: likely or somewhat likely taken branches are made long and 9402 unaligned if possible to avoid branch penalty. */ 9403 9404 bool 9405 arc_branch_size_unknown_p (void) 9406 { 9407 return !optimize_size && arc_reorg_in_progress; 9408 } 9409 9410 /* The usual; we set up our machine_function data. */ 9411 9412 static struct machine_function * 9413 arc_init_machine_status (void) 9414 { 9415 struct machine_function *machine; 9416 machine = ggc_cleared_alloc<machine_function> (); 9417 machine->fn_type = ARC_FUNCTION_UNKNOWN; 9418 9419 return machine; 9420 } 9421 9422 /* Implements INIT_EXPANDERS. We just set up to call the above 9423 function. */ 9424 9425 void 9426 arc_init_expanders (void) 9427 { 9428 init_machine_status = arc_init_machine_status; 9429 } 9430 9431 /* Check if OP is a proper parallel of a millicode call pattern. OFFSET 9432 indicates a number of elements to ignore - that allows to have a 9433 sibcall pattern that starts with (return). LOAD_P is zero for store 9434 multiple (for prologues), and one for load multiples (for epilogues), 9435 and two for load multiples where no final clobber of blink is required. 9436 We also skip the first load / store element since this is supposed to 9437 be checked in the instruction pattern. */ 9438 9439 int 9440 arc_check_millicode (rtx op, int offset, int load_p) 9441 { 9442 int len = XVECLEN (op, 0) - offset; 9443 int i; 9444 9445 if (load_p == 2) 9446 { 9447 if (len < 2 || len > 13) 9448 return 0; 9449 load_p = 1; 9450 } 9451 else 9452 { 9453 rtx elt = XVECEXP (op, 0, --len); 9454 9455 if (GET_CODE (elt) != CLOBBER 9456 || !REG_P (XEXP (elt, 0)) 9457 || REGNO (XEXP (elt, 0)) != RETURN_ADDR_REGNUM 9458 || len < 3 || len > 13) 9459 return 0; 9460 } 9461 for (i = 1; i < len; i++) 9462 { 9463 rtx elt = XVECEXP (op, 0, i + offset); 9464 rtx reg, mem, addr; 9465 9466 if (GET_CODE (elt) != SET) 9467 return 0; 9468 mem = XEXP (elt, load_p); 9469 reg = XEXP (elt, 1-load_p); 9470 if (!REG_P (reg) || REGNO (reg) != 13U+i || !MEM_P (mem)) 9471 return 0; 9472 addr = XEXP (mem, 0); 9473 if (GET_CODE (addr) != PLUS 9474 || !rtx_equal_p (stack_pointer_rtx, XEXP (addr, 0)) 9475 || !CONST_INT_P (XEXP (addr, 1)) || INTVAL (XEXP (addr, 1)) != i*4) 9476 return 0; 9477 } 9478 return 1; 9479 } 9480 9481 /* Accessor functions for cfun->machine->unalign. */ 9482 9483 int 9484 arc_get_unalign (void) 9485 { 9486 return cfun->machine->unalign; 9487 } 9488 9489 void 9490 arc_clear_unalign (void) 9491 { 9492 if (cfun) 9493 cfun->machine->unalign = 0; 9494 } 9495 9496 void 9497 arc_toggle_unalign (void) 9498 { 9499 cfun->machine->unalign ^= 2; 9500 } 9501 9502 /* Operands 0..2 are the operands of a addsi which uses a 12 bit 9503 constant in operand 2, but which would require a LIMM because of 9504 operand mismatch. 9505 operands 3 and 4 are new SET_SRCs for operands 0. */ 9506 9507 void 9508 split_addsi (rtx *operands) 9509 { 9510 int val = INTVAL (operands[2]); 9511 9512 /* Try for two short insns first. Lengths being equal, we prefer 9513 expansions with shorter register lifetimes. */ 9514 if (val > 127 && val <= 255 9515 && satisfies_constraint_Rcq (operands[0])) 9516 { 9517 operands[3] = operands[2]; 9518 operands[4] = gen_rtx_PLUS (SImode, operands[0], operands[1]); 9519 } 9520 else 9521 { 9522 operands[3] = operands[1]; 9523 operands[4] = gen_rtx_PLUS (SImode, operands[0], operands[2]); 9524 } 9525 } 9526 9527 /* Operands 0..2 are the operands of a subsi which uses a 12 bit 9528 constant in operand 1, but which would require a LIMM because of 9529 operand mismatch. 9530 operands 3 and 4 are new SET_SRCs for operands 0. */ 9531 9532 void 9533 split_subsi (rtx *operands) 9534 { 9535 int val = INTVAL (operands[1]); 9536 9537 /* Try for two short insns first. Lengths being equal, we prefer 9538 expansions with shorter register lifetimes. */ 9539 if (satisfies_constraint_Rcq (operands[0]) 9540 && satisfies_constraint_Rcq (operands[2])) 9541 { 9542 if (val >= -31 && val <= 127) 9543 { 9544 operands[3] = gen_rtx_NEG (SImode, operands[2]); 9545 operands[4] = gen_rtx_PLUS (SImode, operands[0], operands[1]); 9546 return; 9547 } 9548 else if (val >= 0 && val < 255) 9549 { 9550 operands[3] = operands[1]; 9551 operands[4] = gen_rtx_MINUS (SImode, operands[0], operands[2]); 9552 return; 9553 } 9554 } 9555 /* If the destination is not an ARCompact16 register, we might 9556 still have a chance to make a short insn if the source is; 9557 we need to start with a reg-reg move for this. */ 9558 operands[3] = operands[2]; 9559 operands[4] = gen_rtx_MINUS (SImode, operands[1], operands[0]); 9560 } 9561 9562 /* Handle DOUBLE_REGS uses. 9563 Operand 0: destination register 9564 Operand 1: source register */ 9565 9566 static bool 9567 arc_process_double_reg_moves (rtx *operands) 9568 { 9569 rtx dest = operands[0]; 9570 rtx src = operands[1]; 9571 9572 enum usesDxState { none, srcDx, destDx, maxDx }; 9573 enum usesDxState state = none; 9574 9575 if (refers_to_regno_p (40, 44, src, 0)) 9576 state = srcDx; 9577 if (refers_to_regno_p (40, 44, dest, 0)) 9578 { 9579 /* Via arc_register_move_cost, we should never see D,D moves. */ 9580 gcc_assert (state == none); 9581 state = destDx; 9582 } 9583 9584 if (state == none) 9585 return false; 9586 9587 if (state == srcDx) 9588 { 9589 /* Without the LR insn, we need to split this into a 9590 sequence of insns which will use the DEXCLx and DADDHxy 9591 insns to be able to read the Dx register in question. */ 9592 if (TARGET_DPFP_DISABLE_LRSR) 9593 { 9594 /* gen *movdf_insn_nolrsr */ 9595 rtx set = gen_rtx_SET (dest, src); 9596 rtx use1 = gen_rtx_USE (VOIDmode, const1_rtx); 9597 emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, use1))); 9598 } 9599 else 9600 { 9601 /* When we have 'mov D, r' or 'mov D, D' then get the target 9602 register pair for use with LR insn. */ 9603 rtx destHigh = simplify_gen_subreg (SImode, dest, DFmode, 9604 TARGET_BIG_ENDIAN ? 0 : 4); 9605 rtx destLow = simplify_gen_subreg (SImode, dest, DFmode, 9606 TARGET_BIG_ENDIAN ? 4 : 0); 9607 9608 /* Produce the two LR insns to get the high and low parts. */ 9609 emit_insn (gen_rtx_SET (destHigh, 9610 gen_rtx_UNSPEC_VOLATILE (Pmode, 9611 gen_rtvec (1, src), 9612 VUNSPEC_ARC_LR_HIGH))); 9613 emit_insn (gen_rtx_SET (destLow, 9614 gen_rtx_UNSPEC_VOLATILE (Pmode, 9615 gen_rtvec (1, src), 9616 VUNSPEC_ARC_LR))); 9617 } 9618 } 9619 else if (state == destDx) 9620 { 9621 /* When we have 'mov r, D' or 'mov D, D' and we have access to the 9622 LR insn get the target register pair. */ 9623 rtx srcHigh = simplify_gen_subreg (SImode, src, DFmode, 9624 TARGET_BIG_ENDIAN ? 0 : 4); 9625 rtx srcLow = simplify_gen_subreg (SImode, src, DFmode, 9626 TARGET_BIG_ENDIAN ? 4 : 0); 9627 9628 emit_insn (gen_dexcl_2op (dest, srcHigh, srcLow)); 9629 } 9630 else 9631 gcc_unreachable (); 9632 9633 return true; 9634 } 9635 9636 /* operands 0..1 are the operands of a 64 bit move instruction. 9637 split it into two moves with operands 2/3 and 4/5. */ 9638 9639 void 9640 arc_split_move (rtx *operands) 9641 { 9642 machine_mode mode = GET_MODE (operands[0]); 9643 int i; 9644 int swap = 0; 9645 rtx xop[4]; 9646 9647 if (TARGET_DPFP) 9648 { 9649 if (arc_process_double_reg_moves (operands)) 9650 return; 9651 } 9652 9653 if (TARGET_LL64 9654 && ((memory_operand (operands[0], mode) 9655 && even_register_operand (operands[1], mode)) 9656 || (memory_operand (operands[1], mode) 9657 && even_register_operand (operands[0], mode)))) 9658 { 9659 emit_move_insn (operands[0], operands[1]); 9660 return; 9661 } 9662 9663 if (TARGET_PLUS_QMACW 9664 && GET_CODE (operands[1]) == CONST_VECTOR) 9665 { 9666 HOST_WIDE_INT intval0, intval1; 9667 if (GET_MODE (operands[1]) == V2SImode) 9668 { 9669 intval0 = INTVAL (XVECEXP (operands[1], 0, 0)); 9670 intval1 = INTVAL (XVECEXP (operands[1], 0, 1)); 9671 } 9672 else 9673 { 9674 intval1 = INTVAL (XVECEXP (operands[1], 0, 3)) << 16; 9675 intval1 |= INTVAL (XVECEXP (operands[1], 0, 2)) & 0xFFFF; 9676 intval0 = INTVAL (XVECEXP (operands[1], 0, 1)) << 16; 9677 intval0 |= INTVAL (XVECEXP (operands[1], 0, 0)) & 0xFFFF; 9678 } 9679 xop[0] = gen_rtx_REG (SImode, REGNO (operands[0])); 9680 xop[3] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1); 9681 xop[2] = GEN_INT (trunc_int_for_mode (intval0, SImode)); 9682 xop[1] = GEN_INT (trunc_int_for_mode (intval1, SImode)); 9683 emit_move_insn (xop[0], xop[2]); 9684 emit_move_insn (xop[3], xop[1]); 9685 return; 9686 } 9687 9688 for (i = 0; i < 2; i++) 9689 { 9690 if (MEM_P (operands[i]) && auto_inc_p (XEXP (operands[i], 0))) 9691 { 9692 rtx addr = XEXP (operands[i], 0); 9693 rtx r, o; 9694 enum rtx_code code; 9695 9696 gcc_assert (!reg_overlap_mentioned_p (operands[0], addr)); 9697 switch (GET_CODE (addr)) 9698 { 9699 case PRE_DEC: o = GEN_INT (-8); goto pre_modify; 9700 case PRE_INC: o = GEN_INT (8); goto pre_modify; 9701 case PRE_MODIFY: o = XEXP (XEXP (addr, 1), 1); 9702 pre_modify: 9703 code = PRE_MODIFY; 9704 break; 9705 case POST_DEC: o = GEN_INT (-8); goto post_modify; 9706 case POST_INC: o = GEN_INT (8); goto post_modify; 9707 case POST_MODIFY: o = XEXP (XEXP (addr, 1), 1); 9708 post_modify: 9709 code = POST_MODIFY; 9710 swap = 2; 9711 break; 9712 default: 9713 gcc_unreachable (); 9714 } 9715 r = XEXP (addr, 0); 9716 xop[0+i] = adjust_automodify_address_nv 9717 (operands[i], SImode, 9718 gen_rtx_fmt_ee (code, Pmode, r, 9719 gen_rtx_PLUS (Pmode, r, o)), 9720 0); 9721 xop[2+i] = adjust_automodify_address_nv 9722 (operands[i], SImode, plus_constant (Pmode, r, 4), 4); 9723 } 9724 else 9725 { 9726 xop[0+i] = operand_subword (operands[i], 0, 0, mode); 9727 xop[2+i] = operand_subword (operands[i], 1, 0, mode); 9728 } 9729 } 9730 if (reg_overlap_mentioned_p (xop[0], xop[3])) 9731 { 9732 swap = 2; 9733 gcc_assert (!reg_overlap_mentioned_p (xop[2], xop[1])); 9734 } 9735 9736 emit_move_insn (xop[0 + swap], xop[1 + swap]); 9737 emit_move_insn (xop[2 - swap], xop[3 - swap]); 9738 9739 } 9740 9741 /* Select between the instruction output templates s_tmpl (for short INSNs) 9742 and l_tmpl (for long INSNs). */ 9743 9744 const char * 9745 arc_short_long (rtx_insn *insn, const char *s_tmpl, const char *l_tmpl) 9746 { 9747 int is_short = arc_verify_short (insn, cfun->machine->unalign, -1); 9748 9749 extract_constrain_insn_cached (insn); 9750 return is_short ? s_tmpl : l_tmpl; 9751 } 9752 9753 /* Searches X for any reference to REGNO, returning the rtx of the 9754 reference found if any. Otherwise, returns NULL_RTX. */ 9755 9756 rtx 9757 arc_regno_use_in (unsigned int regno, rtx x) 9758 { 9759 const char *fmt; 9760 int i, j; 9761 rtx tem; 9762 9763 if (REG_P (x) && refers_to_regno_p (regno, x)) 9764 return x; 9765 9766 fmt = GET_RTX_FORMAT (GET_CODE (x)); 9767 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) 9768 { 9769 if (fmt[i] == 'e') 9770 { 9771 if ((tem = regno_use_in (regno, XEXP (x, i)))) 9772 return tem; 9773 } 9774 else if (fmt[i] == 'E') 9775 for (j = XVECLEN (x, i) - 1; j >= 0; j--) 9776 if ((tem = regno_use_in (regno , XVECEXP (x, i, j)))) 9777 return tem; 9778 } 9779 9780 return NULL_RTX; 9781 } 9782 9783 /* Return the integer value of the "type" attribute for INSN, or -1 if 9784 INSN can't have attributes. */ 9785 9786 static int 9787 arc_attr_type (rtx_insn *insn) 9788 { 9789 if (NONJUMP_INSN_P (insn) 9790 ? (GET_CODE (PATTERN (insn)) == USE 9791 || GET_CODE (PATTERN (insn)) == CLOBBER) 9792 : JUMP_P (insn) 9793 ? (GET_CODE (PATTERN (insn)) == ADDR_VEC 9794 || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC) 9795 : !CALL_P (insn)) 9796 return -1; 9797 return get_attr_type (insn); 9798 } 9799 9800 /* Return true if insn sets the condition codes. */ 9801 9802 bool 9803 arc_sets_cc_p (rtx_insn *insn) 9804 { 9805 if (NONJUMP_INSN_P (insn)) 9806 if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn))) 9807 insn = seq->insn (seq->len () - 1); 9808 return arc_attr_type (insn) == TYPE_COMPARE; 9809 } 9810 9811 /* Return true if INSN is an instruction with a delay slot we may want 9812 to fill. */ 9813 9814 bool 9815 arc_need_delay (rtx_insn *insn) 9816 { 9817 rtx_insn *next; 9818 9819 if (!flag_delayed_branch) 9820 return false; 9821 /* The return at the end of a function needs a delay slot. */ 9822 if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == USE 9823 && (!(next = next_active_insn (insn)) 9824 || ((!NONJUMP_INSN_P (next) || GET_CODE (PATTERN (next)) != SEQUENCE) 9825 && arc_attr_type (next) == TYPE_RETURN)) 9826 && (!TARGET_PAD_RETURN 9827 || (prev_active_insn (insn) 9828 && prev_active_insn (prev_active_insn (insn)) 9829 && prev_active_insn (prev_active_insn (prev_active_insn (insn)))))) 9830 return true; 9831 if (NONJUMP_INSN_P (insn) 9832 ? (GET_CODE (PATTERN (insn)) == USE 9833 || GET_CODE (PATTERN (insn)) == CLOBBER 9834 || GET_CODE (PATTERN (insn)) == SEQUENCE) 9835 : JUMP_P (insn) 9836 ? (GET_CODE (PATTERN (insn)) == ADDR_VEC 9837 || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC) 9838 : !CALL_P (insn)) 9839 return false; 9840 return num_delay_slots (insn) != 0; 9841 } 9842 9843 /* Return true if the scheduling pass(es) has/have already run, 9844 i.e. where possible, we should try to mitigate high latencies 9845 by different instruction selection. */ 9846 9847 bool 9848 arc_scheduling_not_expected (void) 9849 { 9850 return cfun->machine->arc_reorg_started; 9851 } 9852 9853 int 9854 arc_label_align (rtx_insn *label) 9855 { 9856 /* Code has a minimum p2 alignment of 1, which we must restore after an 9857 ADDR_DIFF_VEC. */ 9858 if (align_labels_log < 1) 9859 { 9860 rtx_insn *next = next_nonnote_nondebug_insn (label); 9861 if (INSN_P (next) && recog_memoized (next) >= 0) 9862 return 1; 9863 } 9864 return align_labels_log; 9865 } 9866 9867 /* Return true if LABEL is in executable code. */ 9868 9869 bool 9870 arc_text_label (rtx_insn *label) 9871 { 9872 rtx_insn *next; 9873 9874 /* ??? We use deleted labels like they were still there, see 9875 gcc.c-torture/compile/20000326-2.c . */ 9876 gcc_assert (GET_CODE (label) == CODE_LABEL 9877 || (GET_CODE (label) == NOTE 9878 && NOTE_KIND (label) == NOTE_INSN_DELETED_LABEL)); 9879 next = next_nonnote_insn (label); 9880 if (next) 9881 return (!JUMP_TABLE_DATA_P (next) 9882 || GET_CODE (PATTERN (next)) != ADDR_VEC); 9883 else if (!PREV_INSN (label)) 9884 /* ??? sometimes text labels get inserted very late, see 9885 gcc.dg/torture/stackalign/comp-goto-1.c */ 9886 return true; 9887 return false; 9888 } 9889 9890 /* Without this, gcc.dg/tree-prof/bb-reorg.c fails to assemble 9891 when compiling with -O2 -freorder-blocks-and-partition -fprofile-use 9892 -D_PROFILE_USE; delay branch scheduling then follows a crossing jump 9893 to redirect two breqs. */ 9894 9895 static bool 9896 arc_can_follow_jump (const rtx_insn *follower, const rtx_insn *followee) 9897 { 9898 /* ??? get_attr_type is declared to take an rtx. */ 9899 union { const rtx_insn *c; rtx_insn *r; } u; 9900 9901 u.c = follower; 9902 if (CROSSING_JUMP_P (followee)) 9903 switch (get_attr_type (u.r)) 9904 { 9905 case TYPE_BRANCH: 9906 if (get_attr_length (u.r) != 2) 9907 break; 9908 /* Fall through. */ 9909 case TYPE_BRCC: 9910 case TYPE_BRCC_NO_DELAY_SLOT: 9911 return false; 9912 default: 9913 return true; 9914 } 9915 return true; 9916 } 9917 9918 /* Return the register number of the register holding the return address 9919 for a function of type TYPE. */ 9920 9921 int 9922 arc_return_address_register (unsigned int fn_type) 9923 { 9924 int regno = 0; 9925 9926 if (ARC_INTERRUPT_P (fn_type)) 9927 { 9928 if ((fn_type & (ARC_FUNCTION_ILINK1 | ARC_FUNCTION_FIRQ)) != 0) 9929 regno = ILINK1_REGNUM; 9930 else if ((fn_type & ARC_FUNCTION_ILINK2) != 0) 9931 regno = ILINK2_REGNUM; 9932 else 9933 gcc_unreachable (); 9934 } 9935 else if (ARC_NORMAL_P (fn_type) || ARC_NAKED_P (fn_type)) 9936 regno = RETURN_ADDR_REGNUM; 9937 9938 gcc_assert (regno != 0); 9939 return regno; 9940 } 9941 9942 /* Implement EPILOGUE_USES. 9943 Return true if REGNO should be added to the deemed uses of the epilogue. 9944 9945 We have to make sure all the register restore instructions are 9946 known to be live in interrupt functions, plus the blink register if 9947 it is clobbered by the isr. */ 9948 9949 bool 9950 arc_epilogue_uses (int regno) 9951 { 9952 unsigned int fn_type; 9953 9954 if (regno == arc_tp_regno) 9955 return true; 9956 9957 fn_type = arc_compute_function_type (cfun); 9958 if (reload_completed) 9959 { 9960 if (ARC_INTERRUPT_P (cfun->machine->fn_type)) 9961 { 9962 if (!fixed_regs[regno]) 9963 return true; 9964 return ((regno == arc_return_address_register (fn_type)) 9965 || (regno == RETURN_ADDR_REGNUM)); 9966 } 9967 else 9968 return regno == RETURN_ADDR_REGNUM; 9969 } 9970 else 9971 return regno == arc_return_address_register (fn_type); 9972 } 9973 9974 /* Helper for EH_USES macro. */ 9975 9976 bool 9977 arc_eh_uses (int regno) 9978 { 9979 if (regno == arc_tp_regno) 9980 return true; 9981 return false; 9982 } 9983 9984 #ifndef TARGET_NO_LRA 9985 #define TARGET_NO_LRA !TARGET_LRA 9986 #endif 9987 9988 static bool 9989 arc_lra_p (void) 9990 { 9991 return !TARGET_NO_LRA; 9992 } 9993 9994 /* ??? Should we define TARGET_REGISTER_PRIORITY? We might perfer to use 9995 Rcq registers, because some insn are shorter with them. OTOH we already 9996 have separate alternatives for this purpose, and other insns don't 9997 mind, so maybe we should rather prefer the other registers? 9998 We need more data, and we can only get that if we allow people to 9999 try all options. */ 10000 static int 10001 arc_register_priority (int r) 10002 { 10003 switch (arc_lra_priority_tag) 10004 { 10005 case ARC_LRA_PRIORITY_NONE: 10006 return 0; 10007 case ARC_LRA_PRIORITY_NONCOMPACT: 10008 return ((((r & 7) ^ 4) - 4) & 15) != r; 10009 case ARC_LRA_PRIORITY_COMPACT: 10010 return ((((r & 7) ^ 4) - 4) & 15) == r; 10011 default: 10012 gcc_unreachable (); 10013 } 10014 } 10015 10016 static reg_class_t 10017 arc_spill_class (reg_class_t /* orig_class */, machine_mode) 10018 { 10019 return GENERAL_REGS; 10020 } 10021 10022 bool 10023 arc_legitimize_reload_address (rtx *p, machine_mode mode, int opnum, 10024 int itype) 10025 { 10026 rtx x = *p; 10027 enum reload_type type = (enum reload_type) itype; 10028 10029 if (GET_CODE (x) == PLUS 10030 && CONST_INT_P (XEXP (x, 1)) 10031 && (RTX_OK_FOR_BASE_P (XEXP (x, 0), true) 10032 || (REG_P (XEXP (x, 0)) 10033 && reg_equiv_constant (REGNO (XEXP (x, 0)))))) 10034 { 10035 int scale = GET_MODE_SIZE (mode); 10036 int shift; 10037 rtx index_rtx = XEXP (x, 1); 10038 HOST_WIDE_INT offset = INTVAL (index_rtx), offset_base; 10039 rtx reg, sum, sum2; 10040 10041 if (scale > 4) 10042 scale = 4; 10043 if ((scale-1) & offset) 10044 scale = 1; 10045 shift = scale >> 1; 10046 offset_base 10047 = ((offset + (256 << shift)) 10048 & ((HOST_WIDE_INT)((unsigned HOST_WIDE_INT) -512 << shift))); 10049 /* Sometimes the normal form does not suit DImode. We 10050 could avoid that by using smaller ranges, but that 10051 would give less optimized code when SImode is 10052 prevalent. */ 10053 if (GET_MODE_SIZE (mode) + offset - offset_base <= (256 << shift)) 10054 { 10055 int regno; 10056 10057 reg = XEXP (x, 0); 10058 regno = REGNO (reg); 10059 sum2 = sum = plus_constant (Pmode, reg, offset_base); 10060 10061 if (reg_equiv_constant (regno)) 10062 { 10063 sum2 = plus_constant (Pmode, reg_equiv_constant (regno), 10064 offset_base); 10065 if (GET_CODE (sum2) == PLUS) 10066 sum2 = gen_rtx_CONST (Pmode, sum2); 10067 } 10068 *p = gen_rtx_PLUS (Pmode, sum, GEN_INT (offset - offset_base)); 10069 push_reload (sum2, NULL_RTX, &XEXP (*p, 0), NULL, 10070 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, opnum, 10071 type); 10072 return true; 10073 } 10074 } 10075 /* We must re-recognize what we created before. */ 10076 else if (GET_CODE (x) == PLUS 10077 && GET_CODE (XEXP (x, 0)) == PLUS 10078 && CONST_INT_P (XEXP (XEXP (x, 0), 1)) 10079 && REG_P (XEXP (XEXP (x, 0), 0)) 10080 && CONST_INT_P (XEXP (x, 1))) 10081 { 10082 /* Because this address is so complex, we know it must have 10083 been created by LEGITIMIZE_RELOAD_ADDRESS before; thus, 10084 it is already unshared, and needs no further unsharing. */ 10085 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, 10086 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, opnum, type); 10087 return true; 10088 } 10089 return false; 10090 } 10091 10092 /* Implement TARGET_USE_BY_PIECES_INFRASTRUCTURE_P. */ 10093 10094 static bool 10095 arc_use_by_pieces_infrastructure_p (unsigned HOST_WIDE_INT size, 10096 unsigned int align, 10097 enum by_pieces_operation op, 10098 bool speed_p) 10099 { 10100 /* Let the movmem expander handle small block moves. */ 10101 if (op == MOVE_BY_PIECES) 10102 return false; 10103 10104 return default_use_by_pieces_infrastructure_p (size, align, op, speed_p); 10105 } 10106 10107 /* Emit a (pre) memory barrier around an atomic sequence according to 10108 MODEL. */ 10109 10110 static void 10111 arc_pre_atomic_barrier (enum memmodel model) 10112 { 10113 if (need_atomic_barrier_p (model, true)) 10114 emit_insn (gen_memory_barrier ()); 10115 } 10116 10117 /* Emit a (post) memory barrier around an atomic sequence according to 10118 MODEL. */ 10119 10120 static void 10121 arc_post_atomic_barrier (enum memmodel model) 10122 { 10123 if (need_atomic_barrier_p (model, false)) 10124 emit_insn (gen_memory_barrier ()); 10125 } 10126 10127 /* Expand a compare and swap pattern. */ 10128 10129 static void 10130 emit_unlikely_jump (rtx insn) 10131 { 10132 rtx_insn *jump = emit_jump_insn (insn); 10133 add_reg_br_prob_note (jump, profile_probability::very_unlikely ()); 10134 } 10135 10136 /* Expand code to perform a 8 or 16-bit compare and swap by doing 10137 32-bit compare and swap on the word containing the byte or 10138 half-word. The difference between a weak and a strong CAS is that 10139 the weak version may simply fail. The strong version relies on two 10140 loops, one checks if the SCOND op is succsfully or not, the other 10141 checks if the 32 bit accessed location which contains the 8 or 16 10142 bit datum is not changed by other thread. The first loop is 10143 implemented by the atomic_compare_and_swapsi_1 pattern. The second 10144 loops is implemented by this routine. */ 10145 10146 static void 10147 arc_expand_compare_and_swap_qh (rtx bool_result, rtx result, rtx mem, 10148 rtx oldval, rtx newval, rtx weak, 10149 rtx mod_s, rtx mod_f) 10150 { 10151 rtx addr1 = force_reg (Pmode, XEXP (mem, 0)); 10152 rtx addr = gen_reg_rtx (Pmode); 10153 rtx off = gen_reg_rtx (SImode); 10154 rtx oldv = gen_reg_rtx (SImode); 10155 rtx newv = gen_reg_rtx (SImode); 10156 rtx oldvalue = gen_reg_rtx (SImode); 10157 rtx newvalue = gen_reg_rtx (SImode); 10158 rtx res = gen_reg_rtx (SImode); 10159 rtx resv = gen_reg_rtx (SImode); 10160 rtx memsi, val, mask, end_label, loop_label, cc, x; 10161 machine_mode mode; 10162 bool is_weak = (weak != const0_rtx); 10163 10164 /* Truncate the address. */ 10165 emit_insn (gen_rtx_SET (addr, 10166 gen_rtx_AND (Pmode, addr1, GEN_INT (-4)))); 10167 10168 /* Compute the datum offset. */ 10169 emit_insn (gen_rtx_SET (off, 10170 gen_rtx_AND (SImode, addr1, GEN_INT (3)))); 10171 if (TARGET_BIG_ENDIAN) 10172 emit_insn (gen_rtx_SET (off, 10173 gen_rtx_MINUS (SImode, 10174 (GET_MODE (mem) == QImode) ? 10175 GEN_INT (3) : GEN_INT (2), off))); 10176 10177 /* Normal read from truncated address. */ 10178 memsi = gen_rtx_MEM (SImode, addr); 10179 set_mem_alias_set (memsi, ALIAS_SET_MEMORY_BARRIER); 10180 MEM_VOLATILE_P (memsi) = MEM_VOLATILE_P (mem); 10181 10182 val = copy_to_reg (memsi); 10183 10184 /* Convert the offset in bits. */ 10185 emit_insn (gen_rtx_SET (off, 10186 gen_rtx_ASHIFT (SImode, off, GEN_INT (3)))); 10187 10188 /* Get the proper mask. */ 10189 if (GET_MODE (mem) == QImode) 10190 mask = force_reg (SImode, GEN_INT (0xff)); 10191 else 10192 mask = force_reg (SImode, GEN_INT (0xffff)); 10193 10194 emit_insn (gen_rtx_SET (mask, 10195 gen_rtx_ASHIFT (SImode, mask, off))); 10196 10197 /* Prepare the old and new values. */ 10198 emit_insn (gen_rtx_SET (val, 10199 gen_rtx_AND (SImode, gen_rtx_NOT (SImode, mask), 10200 val))); 10201 10202 oldval = gen_lowpart (SImode, oldval); 10203 emit_insn (gen_rtx_SET (oldv, 10204 gen_rtx_ASHIFT (SImode, oldval, off))); 10205 10206 newval = gen_lowpart_common (SImode, newval); 10207 emit_insn (gen_rtx_SET (newv, 10208 gen_rtx_ASHIFT (SImode, newval, off))); 10209 10210 emit_insn (gen_rtx_SET (oldv, 10211 gen_rtx_AND (SImode, oldv, mask))); 10212 10213 emit_insn (gen_rtx_SET (newv, 10214 gen_rtx_AND (SImode, newv, mask))); 10215 10216 if (!is_weak) 10217 { 10218 end_label = gen_label_rtx (); 10219 loop_label = gen_label_rtx (); 10220 emit_label (loop_label); 10221 } 10222 10223 /* Make the old and new values. */ 10224 emit_insn (gen_rtx_SET (oldvalue, 10225 gen_rtx_IOR (SImode, oldv, val))); 10226 10227 emit_insn (gen_rtx_SET (newvalue, 10228 gen_rtx_IOR (SImode, newv, val))); 10229 10230 /* Try an 32bit atomic compare and swap. It clobbers the CC 10231 register. */ 10232 emit_insn (gen_atomic_compare_and_swapsi_1 (res, memsi, oldvalue, newvalue, 10233 weak, mod_s, mod_f)); 10234 10235 /* Regardless of the weakness of the operation, a proper boolean 10236 result needs to be provided. */ 10237 x = gen_rtx_REG (CC_Zmode, CC_REG); 10238 x = gen_rtx_EQ (SImode, x, const0_rtx); 10239 emit_insn (gen_rtx_SET (bool_result, x)); 10240 10241 if (!is_weak) 10242 { 10243 /* Check the results: if the atomic op is successfully the goto 10244 to end label. */ 10245 x = gen_rtx_REG (CC_Zmode, CC_REG); 10246 x = gen_rtx_EQ (VOIDmode, x, const0_rtx); 10247 x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, 10248 gen_rtx_LABEL_REF (Pmode, end_label), pc_rtx); 10249 emit_jump_insn (gen_rtx_SET (pc_rtx, x)); 10250 10251 /* Wait for the right moment when the accessed 32-bit location 10252 is stable. */ 10253 emit_insn (gen_rtx_SET (resv, 10254 gen_rtx_AND (SImode, gen_rtx_NOT (SImode, mask), 10255 res))); 10256 mode = SELECT_CC_MODE (NE, resv, val); 10257 cc = gen_rtx_REG (mode, CC_REG); 10258 emit_insn (gen_rtx_SET (cc, gen_rtx_COMPARE (mode, resv, val))); 10259 10260 /* Set the new value of the 32 bit location, proper masked. */ 10261 emit_insn (gen_rtx_SET (val, resv)); 10262 10263 /* Try again if location is unstable. Fall through if only 10264 scond op failed. */ 10265 x = gen_rtx_NE (VOIDmode, cc, const0_rtx); 10266 x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, 10267 gen_rtx_LABEL_REF (Pmode, loop_label), pc_rtx); 10268 emit_unlikely_jump (gen_rtx_SET (pc_rtx, x)); 10269 10270 emit_label (end_label); 10271 } 10272 10273 /* End: proper return the result for the given mode. */ 10274 emit_insn (gen_rtx_SET (res, 10275 gen_rtx_AND (SImode, res, mask))); 10276 10277 emit_insn (gen_rtx_SET (res, 10278 gen_rtx_LSHIFTRT (SImode, res, off))); 10279 10280 emit_move_insn (result, gen_lowpart (GET_MODE (result), res)); 10281 } 10282 10283 /* Helper function used by "atomic_compare_and_swap" expand 10284 pattern. */ 10285 10286 void 10287 arc_expand_compare_and_swap (rtx operands[]) 10288 { 10289 rtx bval, rval, mem, oldval, newval, is_weak, mod_s, mod_f, x; 10290 machine_mode mode; 10291 10292 bval = operands[0]; 10293 rval = operands[1]; 10294 mem = operands[2]; 10295 oldval = operands[3]; 10296 newval = operands[4]; 10297 is_weak = operands[5]; 10298 mod_s = operands[6]; 10299 mod_f = operands[7]; 10300 mode = GET_MODE (mem); 10301 10302 if (reg_overlap_mentioned_p (rval, oldval)) 10303 oldval = copy_to_reg (oldval); 10304 10305 if (mode == SImode) 10306 { 10307 emit_insn (gen_atomic_compare_and_swapsi_1 (rval, mem, oldval, newval, 10308 is_weak, mod_s, mod_f)); 10309 x = gen_rtx_REG (CC_Zmode, CC_REG); 10310 x = gen_rtx_EQ (SImode, x, const0_rtx); 10311 emit_insn (gen_rtx_SET (bval, x)); 10312 } 10313 else 10314 { 10315 arc_expand_compare_and_swap_qh (bval, rval, mem, oldval, newval, 10316 is_weak, mod_s, mod_f); 10317 } 10318 } 10319 10320 /* Helper function used by the "atomic_compare_and_swapsi_1" 10321 pattern. */ 10322 10323 void 10324 arc_split_compare_and_swap (rtx operands[]) 10325 { 10326 rtx rval, mem, oldval, newval; 10327 machine_mode mode; 10328 enum memmodel mod_s, mod_f; 10329 bool is_weak; 10330 rtx label1, label2, x, cond; 10331 10332 rval = operands[0]; 10333 mem = operands[1]; 10334 oldval = operands[2]; 10335 newval = operands[3]; 10336 is_weak = (operands[4] != const0_rtx); 10337 mod_s = (enum memmodel) INTVAL (operands[5]); 10338 mod_f = (enum memmodel) INTVAL (operands[6]); 10339 mode = GET_MODE (mem); 10340 10341 /* ARC atomic ops work only with 32-bit aligned memories. */ 10342 gcc_assert (mode == SImode); 10343 10344 arc_pre_atomic_barrier (mod_s); 10345 10346 label1 = NULL_RTX; 10347 if (!is_weak) 10348 { 10349 label1 = gen_label_rtx (); 10350 emit_label (label1); 10351 } 10352 label2 = gen_label_rtx (); 10353 10354 /* Load exclusive. */ 10355 emit_insn (gen_arc_load_exclusivesi (rval, mem)); 10356 10357 /* Check if it is oldval. */ 10358 mode = SELECT_CC_MODE (NE, rval, oldval); 10359 cond = gen_rtx_REG (mode, CC_REG); 10360 emit_insn (gen_rtx_SET (cond, gen_rtx_COMPARE (mode, rval, oldval))); 10361 10362 x = gen_rtx_NE (VOIDmode, cond, const0_rtx); 10363 x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, 10364 gen_rtx_LABEL_REF (Pmode, label2), pc_rtx); 10365 emit_unlikely_jump (gen_rtx_SET (pc_rtx, x)); 10366 10367 /* Exclusively store new item. Store clobbers CC reg. */ 10368 emit_insn (gen_arc_store_exclusivesi (mem, newval)); 10369 10370 if (!is_weak) 10371 { 10372 /* Check the result of the store. */ 10373 cond = gen_rtx_REG (CC_Zmode, CC_REG); 10374 x = gen_rtx_NE (VOIDmode, cond, const0_rtx); 10375 x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, 10376 gen_rtx_LABEL_REF (Pmode, label1), pc_rtx); 10377 emit_unlikely_jump (gen_rtx_SET (pc_rtx, x)); 10378 } 10379 10380 if (mod_f != MEMMODEL_RELAXED) 10381 emit_label (label2); 10382 10383 arc_post_atomic_barrier (mod_s); 10384 10385 if (mod_f == MEMMODEL_RELAXED) 10386 emit_label (label2); 10387 } 10388 10389 /* Expand an atomic fetch-and-operate pattern. CODE is the binary operation 10390 to perform. MEM is the memory on which to operate. VAL is the second 10391 operand of the binary operator. BEFORE and AFTER are optional locations to 10392 return the value of MEM either before of after the operation. MODEL_RTX 10393 is a CONST_INT containing the memory model to use. */ 10394 10395 void 10396 arc_expand_atomic_op (enum rtx_code code, rtx mem, rtx val, 10397 rtx orig_before, rtx orig_after, rtx model_rtx) 10398 { 10399 enum memmodel model = (enum memmodel) INTVAL (model_rtx); 10400 machine_mode mode = GET_MODE (mem); 10401 rtx label, x, cond; 10402 rtx before = orig_before, after = orig_after; 10403 10404 /* ARC atomic ops work only with 32-bit aligned memories. */ 10405 gcc_assert (mode == SImode); 10406 10407 arc_pre_atomic_barrier (model); 10408 10409 label = gen_label_rtx (); 10410 emit_label (label); 10411 label = gen_rtx_LABEL_REF (VOIDmode, label); 10412 10413 if (before == NULL_RTX) 10414 before = gen_reg_rtx (mode); 10415 10416 if (after == NULL_RTX) 10417 after = gen_reg_rtx (mode); 10418 10419 /* Load exclusive. */ 10420 emit_insn (gen_arc_load_exclusivesi (before, mem)); 10421 10422 switch (code) 10423 { 10424 case NOT: 10425 x = gen_rtx_AND (mode, before, val); 10426 emit_insn (gen_rtx_SET (after, x)); 10427 x = gen_rtx_NOT (mode, after); 10428 emit_insn (gen_rtx_SET (after, x)); 10429 break; 10430 10431 case MINUS: 10432 if (CONST_INT_P (val)) 10433 { 10434 val = GEN_INT (-INTVAL (val)); 10435 code = PLUS; 10436 } 10437 10438 /* FALLTHRU. */ 10439 default: 10440 x = gen_rtx_fmt_ee (code, mode, before, val); 10441 emit_insn (gen_rtx_SET (after, x)); 10442 break; 10443 } 10444 10445 /* Exclusively store new item. Store clobbers CC reg. */ 10446 emit_insn (gen_arc_store_exclusivesi (mem, after)); 10447 10448 /* Check the result of the store. */ 10449 cond = gen_rtx_REG (CC_Zmode, CC_REG); 10450 x = gen_rtx_NE (VOIDmode, cond, const0_rtx); 10451 x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, 10452 label, pc_rtx); 10453 emit_unlikely_jump (gen_rtx_SET (pc_rtx, x)); 10454 10455 arc_post_atomic_barrier (model); 10456 } 10457 10458 /* Implement TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P. */ 10459 10460 static bool 10461 arc_no_speculation_in_delay_slots_p () 10462 { 10463 return true; 10464 } 10465 10466 /* Return a parallel of registers to represent where to find the 10467 register pieces if required, otherwise NULL_RTX. */ 10468 10469 static rtx 10470 arc_dwarf_register_span (rtx rtl) 10471 { 10472 machine_mode mode = GET_MODE (rtl); 10473 unsigned regno; 10474 rtx p; 10475 10476 if (GET_MODE_SIZE (mode) != 8) 10477 return NULL_RTX; 10478 10479 p = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2)); 10480 regno = REGNO (rtl); 10481 XVECEXP (p, 0, 0) = gen_rtx_REG (SImode, regno); 10482 XVECEXP (p, 0, 1) = gen_rtx_REG (SImode, regno + 1); 10483 10484 return p; 10485 } 10486 10487 /* Return true if OP is an acceptable memory operand for ARCompact 10488 16-bit load instructions of MODE. 10489 10490 AV2SHORT: TRUE if address needs to fit into the new ARCv2 short 10491 non scaled instructions. 10492 10493 SCALED: TRUE if address can be scaled. */ 10494 10495 bool 10496 compact_memory_operand_p (rtx op, machine_mode mode, 10497 bool av2short, bool scaled) 10498 { 10499 rtx addr, plus0, plus1; 10500 int size, off; 10501 10502 /* Eliminate non-memory operations. */ 10503 if (GET_CODE (op) != MEM) 10504 return 0; 10505 10506 /* .di instructions have no 16-bit form. */ 10507 if (MEM_VOLATILE_P (op) && !TARGET_VOLATILE_CACHE_SET) 10508 return false; 10509 10510 if (mode == VOIDmode) 10511 mode = GET_MODE (op); 10512 10513 size = GET_MODE_SIZE (mode); 10514 10515 /* dword operations really put out 2 instructions, so eliminate 10516 them. */ 10517 if (size > UNITS_PER_WORD) 10518 return false; 10519 10520 /* Decode the address now. */ 10521 addr = XEXP (op, 0); 10522 switch (GET_CODE (addr)) 10523 { 10524 case REG: 10525 return (REGNO (addr) >= FIRST_PSEUDO_REGISTER 10526 || COMPACT_GP_REG_P (REGNO (addr)) 10527 || (SP_REG_P (REGNO (addr)) && (size != 2))); 10528 case PLUS: 10529 plus0 = XEXP (addr, 0); 10530 plus1 = XEXP (addr, 1); 10531 10532 if ((GET_CODE (plus0) == REG) 10533 && ((REGNO (plus0) >= FIRST_PSEUDO_REGISTER) 10534 || COMPACT_GP_REG_P (REGNO (plus0))) 10535 && ((GET_CODE (plus1) == REG) 10536 && ((REGNO (plus1) >= FIRST_PSEUDO_REGISTER) 10537 || COMPACT_GP_REG_P (REGNO (plus1))))) 10538 { 10539 return !av2short; 10540 } 10541 10542 if ((GET_CODE (plus0) == REG) 10543 && ((REGNO (plus0) >= FIRST_PSEUDO_REGISTER) 10544 || (COMPACT_GP_REG_P (REGNO (plus0)) && !av2short) 10545 || (IN_RANGE (REGNO (plus0), 0, 31) && av2short)) 10546 && (GET_CODE (plus1) == CONST_INT)) 10547 { 10548 bool valid = false; 10549 10550 off = INTVAL (plus1); 10551 10552 /* Negative offset is not supported in 16-bit load/store insns. */ 10553 if (off < 0) 10554 return 0; 10555 10556 /* Only u5 immediates allowed in code density instructions. */ 10557 if (av2short) 10558 { 10559 switch (size) 10560 { 10561 case 1: 10562 return false; 10563 case 2: 10564 /* This is an ldh_s.x instruction, check the u6 10565 immediate. */ 10566 if (COMPACT_GP_REG_P (REGNO (plus0))) 10567 valid = true; 10568 break; 10569 case 4: 10570 /* Only u5 immediates allowed in 32bit access code 10571 density instructions. */ 10572 if (REGNO (plus0) <= 31) 10573 return ((off < 32) && (off % 4 == 0)); 10574 break; 10575 default: 10576 return false; 10577 } 10578 } 10579 else 10580 if (COMPACT_GP_REG_P (REGNO (plus0))) 10581 valid = true; 10582 10583 if (valid) 10584 { 10585 10586 switch (size) 10587 { 10588 case 1: 10589 return (off < 32); 10590 case 2: 10591 /* The 6-bit constant get shifted to fit the real 10592 5-bits field. Check also for the alignment. */ 10593 return ((off < 64) && (off % 2 == 0)); 10594 case 4: 10595 return ((off < 128) && (off % 4 == 0)); 10596 default: 10597 return false; 10598 } 10599 } 10600 } 10601 10602 if (REG_P (plus0) && CONST_INT_P (plus1) 10603 && ((REGNO (plus0) >= FIRST_PSEUDO_REGISTER) 10604 || SP_REG_P (REGNO (plus0))) 10605 && !av2short) 10606 { 10607 off = INTVAL (plus1); 10608 return ((size != 2) && (off >= 0 && off < 128) && (off % 4 == 0)); 10609 } 10610 10611 if ((GET_CODE (plus0) == MULT) 10612 && (GET_CODE (XEXP (plus0, 0)) == REG) 10613 && ((REGNO (XEXP (plus0, 0)) >= FIRST_PSEUDO_REGISTER) 10614 || COMPACT_GP_REG_P (REGNO (XEXP (plus0, 0)))) 10615 && (GET_CODE (plus1) == REG) 10616 && ((REGNO (plus1) >= FIRST_PSEUDO_REGISTER) 10617 || COMPACT_GP_REG_P (REGNO (plus1)))) 10618 return scaled; 10619 default: 10620 break ; 10621 /* TODO: 'gp' and 'pcl' are to supported as base address operand 10622 for 16-bit load instructions. */ 10623 } 10624 return false; 10625 } 10626 10627 /* Return the frame pointer value to be backed up in the setjmp buffer. */ 10628 10629 static rtx 10630 arc_builtin_setjmp_frame_value (void) 10631 { 10632 /* We always want to preserve whatever value is currently in the frame 10633 pointer register. For frames that are using the frame pointer the new 10634 value of the frame pointer register will have already been computed 10635 (as part of the prologue). For frames that are not using the frame 10636 pointer it is important that we backup whatever value is in the frame 10637 pointer register, as earlier (more outer) frames may have placed a 10638 value into the frame pointer register. It might be tempting to try 10639 and use `frame_pointer_rtx` here, however, this is not what we want. 10640 For frames that are using the frame pointer this will give the 10641 correct value. However, for frames that are not using the frame 10642 pointer this will still give the value that _would_ have been the 10643 frame pointer value for this frame (if the use of the frame pointer 10644 had not been removed). We really do want the raw frame pointer 10645 register value. */ 10646 return gen_raw_REG (Pmode, FRAME_POINTER_REGNUM); 10647 } 10648 10649 /* Return nonzero if a jli call should be generated for a call from 10650 the current function to DECL. */ 10651 10652 bool 10653 arc_is_jli_call_p (rtx pat) 10654 { 10655 tree attrs; 10656 tree decl = SYMBOL_REF_DECL (pat); 10657 10658 /* If it is not a well defined public function then return false. */ 10659 if (!decl || !SYMBOL_REF_FUNCTION_P (pat) || !TREE_PUBLIC (decl)) 10660 return false; 10661 10662 attrs = TYPE_ATTRIBUTES (TREE_TYPE (decl)); 10663 if (lookup_attribute ("jli_always", attrs)) 10664 return true; 10665 10666 if (lookup_attribute ("jli_fixed", attrs)) 10667 return true; 10668 10669 return TARGET_JLI_ALWAYS; 10670 } 10671 10672 /* Handle and "jli" attribute; arguments as in struct 10673 attribute_spec.handler. */ 10674 10675 static tree 10676 arc_handle_jli_attribute (tree *node ATTRIBUTE_UNUSED, 10677 tree name, tree args, int, 10678 bool *no_add_attrs) 10679 { 10680 if (!TARGET_V2) 10681 { 10682 warning (OPT_Wattributes, 10683 "%qE attribute only valid for ARCv2 architecture", 10684 name); 10685 *no_add_attrs = true; 10686 } 10687 10688 if (args == NULL_TREE) 10689 { 10690 warning (OPT_Wattributes, 10691 "argument of %qE attribute is missing", 10692 name); 10693 *no_add_attrs = true; 10694 } 10695 else 10696 { 10697 if (TREE_CODE (TREE_VALUE (args)) == NON_LVALUE_EXPR) 10698 TREE_VALUE (args) = TREE_OPERAND (TREE_VALUE (args), 0); 10699 tree arg = TREE_VALUE (args); 10700 if (TREE_CODE (arg) != INTEGER_CST) 10701 { 10702 warning (0, "%qE attribute allows only an integer constant argument", 10703 name); 10704 *no_add_attrs = true; 10705 } 10706 /* FIXME! add range check. TREE_INT_CST_LOW (arg) */ 10707 } 10708 return NULL_TREE; 10709 } 10710 10711 /* Handle and "scure" attribute; arguments as in struct 10712 attribute_spec.handler. */ 10713 10714 static tree 10715 arc_handle_secure_attribute (tree *node ATTRIBUTE_UNUSED, 10716 tree name, tree args, int, 10717 bool *no_add_attrs) 10718 { 10719 if (!TARGET_EM) 10720 { 10721 warning (OPT_Wattributes, 10722 "%qE attribute only valid for ARC EM architecture", 10723 name); 10724 *no_add_attrs = true; 10725 } 10726 10727 if (args == NULL_TREE) 10728 { 10729 warning (OPT_Wattributes, 10730 "argument of %qE attribute is missing", 10731 name); 10732 *no_add_attrs = true; 10733 } 10734 else 10735 { 10736 if (TREE_CODE (TREE_VALUE (args)) == NON_LVALUE_EXPR) 10737 TREE_VALUE (args) = TREE_OPERAND (TREE_VALUE (args), 0); 10738 tree arg = TREE_VALUE (args); 10739 if (TREE_CODE (arg) != INTEGER_CST) 10740 { 10741 warning (0, "%qE attribute allows only an integer constant argument", 10742 name); 10743 *no_add_attrs = true; 10744 } 10745 } 10746 return NULL_TREE; 10747 } 10748 10749 /* Return nonzero if the symbol is a secure function. */ 10750 10751 bool 10752 arc_is_secure_call_p (rtx pat) 10753 { 10754 tree attrs; 10755 tree decl = SYMBOL_REF_DECL (pat); 10756 10757 if (!decl) 10758 return false; 10759 10760 attrs = TYPE_ATTRIBUTES (TREE_TYPE (decl)); 10761 if (lookup_attribute ("secure_call", attrs)) 10762 return true; 10763 10764 return false; 10765 } 10766 10767 /* Handle "uncached" qualifier. */ 10768 10769 static tree 10770 arc_handle_uncached_attribute (tree *node, 10771 tree name, tree args, 10772 int flags ATTRIBUTE_UNUSED, 10773 bool *no_add_attrs) 10774 { 10775 if (DECL_P (*node) && TREE_CODE (*node) != TYPE_DECL) 10776 { 10777 error ("%qE attribute only applies to types", 10778 name); 10779 *no_add_attrs = true; 10780 } 10781 else if (args) 10782 { 10783 warning (OPT_Wattributes, "argument of %qE attribute ignored", name); 10784 } 10785 return NULL_TREE; 10786 } 10787 10788 /* Return TRUE if PAT is a memory addressing an uncached data. */ 10789 10790 bool 10791 arc_is_uncached_mem_p (rtx pat) 10792 { 10793 tree attrs; 10794 tree ttype; 10795 struct mem_attrs *refattrs; 10796 10797 if (!MEM_P (pat)) 10798 return false; 10799 10800 /* Get the memory attributes. */ 10801 refattrs = MEM_ATTRS (pat); 10802 if (!refattrs 10803 || !refattrs->expr) 10804 return false; 10805 10806 /* Get the type declaration. */ 10807 ttype = TREE_TYPE (refattrs->expr); 10808 if (!ttype) 10809 return false; 10810 10811 /* Get the type attributes. */ 10812 attrs = TYPE_ATTRIBUTES (ttype); 10813 if (lookup_attribute ("uncached", attrs)) 10814 return true; 10815 return false; 10816 } 10817 10818 /* Handle aux attribute. The auxiliary registers are addressed using 10819 special instructions lr and sr. The attribute 'aux' indicates if a 10820 variable refers to the aux-regs and what is the register number 10821 desired. */ 10822 10823 static tree 10824 arc_handle_aux_attribute (tree *node, 10825 tree name, tree args, int, 10826 bool *no_add_attrs) 10827 { 10828 /* Isn't it better to use address spaces for the aux-regs? */ 10829 if (DECL_P (*node)) 10830 { 10831 if (TREE_CODE (*node) != VAR_DECL) 10832 { 10833 error ("%qE attribute only applies to variables", name); 10834 *no_add_attrs = true; 10835 } 10836 else if (args) 10837 { 10838 if (TREE_CODE (TREE_VALUE (args)) == NON_LVALUE_EXPR) 10839 TREE_VALUE (args) = TREE_OPERAND (TREE_VALUE (args), 0); 10840 tree arg = TREE_VALUE (args); 10841 if (TREE_CODE (arg) != INTEGER_CST) 10842 { 10843 warning (0, "%qE attribute allows only an integer " 10844 "constant argument", name); 10845 *no_add_attrs = true; 10846 } 10847 /* FIXME! add range check. TREE_INT_CST_LOW (arg) */ 10848 } 10849 10850 if (TREE_CODE (*node) == VAR_DECL) 10851 { 10852 tree fntype = TREE_TYPE (*node); 10853 if (fntype && TREE_CODE (fntype) == POINTER_TYPE) 10854 { 10855 tree attrs = tree_cons (get_identifier ("aux"), NULL_TREE, 10856 TYPE_ATTRIBUTES (fntype)); 10857 TYPE_ATTRIBUTES (fntype) = attrs; 10858 } 10859 } 10860 } 10861 return NULL_TREE; 10862 } 10863 10864 /* Implement TARGET_USE_ANCHORS_FOR_SYMBOL_P. We don't want to use 10865 anchors for small data: the GP register acts as an anchor in that 10866 case. We also don't want to use them for PC-relative accesses, 10867 where the PC acts as an anchor. Prohibit also TLS symbols to use 10868 anchors. */ 10869 10870 static bool 10871 arc_use_anchors_for_symbol_p (const_rtx symbol) 10872 { 10873 if (SYMBOL_REF_TLS_MODEL (symbol)) 10874 return false; 10875 10876 if (flag_pic) 10877 return false; 10878 10879 if (SYMBOL_REF_SMALL_P (symbol)) 10880 return false; 10881 10882 return default_use_anchors_for_symbol_p (symbol); 10883 } 10884 10885 /* Return true if SUBST can't safely replace its equivalent during RA. */ 10886 static bool 10887 arc_cannot_substitute_mem_equiv_p (rtx) 10888 { 10889 /* If SUBST is mem[base+index], the address may not fit ISA, 10890 thus return true. */ 10891 return true; 10892 } 10893 10894 #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P 10895 #define TARGET_USE_ANCHORS_FOR_SYMBOL_P arc_use_anchors_for_symbol_p 10896 10897 #undef TARGET_CONSTANT_ALIGNMENT 10898 #define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings 10899 10900 #undef TARGET_CANNOT_SUBSTITUTE_MEM_EQUIV_P 10901 #define TARGET_CANNOT_SUBSTITUTE_MEM_EQUIV_P arc_cannot_substitute_mem_equiv_p 10902 10903 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE 10904 #define TARGET_ASM_TRAMPOLINE_TEMPLATE arc_asm_trampoline_template 10905 10906 struct gcc_target targetm = TARGET_INITIALIZER; 10907 10908 #include "gt-arc.h" 10909