📄 xtensa.c
字号:
if (reverse_regs) { rtx temp = cmp0; cmp0 = cmp1; cmp1 = temp; } brtmp = gen_rtx_REG (CCmode, FPCC_REGNUM); emit_insn (gen_fn (brtmp, cmp0, cmp1)); return gen_rtx_fmt_ee (invert ? EQ : NE, VOIDmode, brtmp, const0_rtx);}voidxtensa_expand_conditional_branch (rtx *operands, enum rtx_code test_code){ enum cmp_type type = branch_type; rtx cmp0 = branch_cmp[0]; rtx cmp1 = branch_cmp[1]; rtx cmp; int invert; rtx label1, label2; switch (type) { case CMP_DF: default: fatal_insn ("bad test", gen_rtx_fmt_ee (test_code, VOIDmode, cmp0, cmp1)); case CMP_SI: invert = FALSE; cmp = gen_int_relational (test_code, cmp0, cmp1, &invert); break; case CMP_SF: if (!TARGET_HARD_FLOAT) fatal_insn ("bad test", gen_rtx_fmt_ee (test_code, VOIDmode, cmp0, cmp1)); invert = FALSE; cmp = gen_float_relational (test_code, cmp0, cmp1); break; } /* Generate the branch. */ label1 = gen_rtx_LABEL_REF (VOIDmode, operands[0]); label2 = pc_rtx; if (invert) { label2 = label1; label1 = pc_rtx; } emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, gen_rtx_IF_THEN_ELSE (VOIDmode, cmp, label1, label2)));}static rtxgen_conditional_move (rtx cmp){ enum rtx_code code = GET_CODE (cmp); rtx op0 = branch_cmp[0]; rtx op1 = branch_cmp[1]; if (branch_type == CMP_SI) { /* Jump optimization calls get_condition() which canonicalizes comparisons like (GE x <const>) to (GT x <const-1>). Transform those comparisons back to GE, since that is the comparison supported in Xtensa. We shouldn't have to transform <LE x const> comparisons, because neither xtensa_expand_conditional_branch() nor get_condition() will produce them. */ if ((code == GT) && (op1 == constm1_rtx)) { code = GE; op1 = const0_rtx; } cmp = gen_rtx_fmt_ee (code, VOIDmode, cc0_rtx, const0_rtx); if (boolean_operator (cmp, VOIDmode)) { /* Swap the operands to make const0 second. */ if (op0 == const0_rtx) { op0 = op1; op1 = const0_rtx; } /* If not comparing against zero, emit a comparison (subtract). */ if (op1 != const0_rtx) { op0 = expand_binop (SImode, sub_optab, op0, op1, 0, 0, OPTAB_LIB_WIDEN); op1 = const0_rtx; } } else if (branch_operator (cmp, VOIDmode)) { /* Swap the operands to make const0 second. */ if (op0 == const0_rtx) { op0 = op1; op1 = const0_rtx; switch (code) { case LT: code = GE; break; case GE: code = LT; break; default: abort (); } } if (op1 != const0_rtx) return 0; } else return 0; return gen_rtx_fmt_ee (code, VOIDmode, op0, op1); } if (TARGET_HARD_FLOAT && (branch_type == CMP_SF)) return gen_float_relational (code, op0, op1); return 0;}intxtensa_expand_conditional_move (rtx *operands, int isflt){ rtx cmp; rtx (*gen_fn) (rtx, rtx, rtx, rtx, rtx); if (!(cmp = gen_conditional_move (operands[1]))) return 0; if (isflt) gen_fn = (branch_type == CMP_SI ? gen_movsfcc_internal0 : gen_movsfcc_internal1); else gen_fn = (branch_type == CMP_SI ? gen_movsicc_internal0 : gen_movsicc_internal1); emit_insn (gen_fn (operands[0], XEXP (cmp, 0), operands[2], operands[3], cmp)); return 1;}intxtensa_expand_scc (rtx *operands){ rtx dest = operands[0]; rtx cmp = operands[1]; rtx one_tmp, zero_tmp; rtx (*gen_fn) (rtx, rtx, rtx, rtx, rtx); if (!(cmp = gen_conditional_move (cmp))) return 0; one_tmp = gen_reg_rtx (SImode); zero_tmp = gen_reg_rtx (SImode); emit_insn (gen_movsi (one_tmp, const_true_rtx)); emit_insn (gen_movsi (zero_tmp, const0_rtx)); gen_fn = (branch_type == CMP_SI ? gen_movsicc_internal0 : gen_movsicc_internal1); emit_insn (gen_fn (dest, XEXP (cmp, 0), one_tmp, zero_tmp, cmp)); return 1;}/* Split OP[1] into OP[2,3] and likewise for OP[0] into OP[0,1]. MODE is for the output, i.e., the input operands are twice as big as MODE. */voidxtensa_split_operand_pair (rtx operands[4], enum machine_mode mode){ switch (GET_CODE (operands[1])) { case REG: operands[3] = gen_rtx_REG (mode, REGNO (operands[1]) + 1); operands[2] = gen_rtx_REG (mode, REGNO (operands[1])); break; case MEM: operands[3] = adjust_address (operands[1], mode, GET_MODE_SIZE (mode)); operands[2] = adjust_address (operands[1], mode, 0); break; case CONST_INT: case CONST_DOUBLE: split_double (operands[1], &operands[2], &operands[3]); break; default: abort (); } switch (GET_CODE (operands[0])) { case REG: operands[1] = gen_rtx_REG (mode, REGNO (operands[0]) + 1); operands[0] = gen_rtx_REG (mode, REGNO (operands[0])); break; case MEM: operands[1] = adjust_address (operands[0], mode, GET_MODE_SIZE (mode)); operands[0] = adjust_address (operands[0], mode, 0); break; default: abort (); }}/* Emit insns to move operands[1] into operands[0]. Return 1 if we have written out everything that needs to be done to do the move. Otherwise, return 0 and the caller will emit the move normally. */intxtensa_emit_move_sequence (rtx *operands, enum machine_mode mode){ if (CONSTANT_P (operands[1]) && (GET_CODE (operands[1]) != CONST_INT || !xtensa_simm12b (INTVAL (operands[1])))) { if (!TARGET_CONST16) operands[1] = force_const_mem (SImode, operands[1]); /* PC-relative loads are always SImode, and CONST16 is only supported in the movsi pattern, so add a SUBREG for any other (smaller) mode. */ if (mode != SImode) { if (register_operand (operands[0], mode)) { operands[0] = simplify_gen_subreg (SImode, operands[0], mode, 0); emit_move_insn (operands[0], operands[1]); return 1; } else { operands[1] = force_reg (SImode, operands[1]); operands[1] = gen_lowpart_SUBREG (mode, operands[1]); } } } if (!(reload_in_progress | reload_completed) && !xtensa_valid_move (mode, operands)) operands[1] = force_reg (mode, operands[1]); operands[1] = xtensa_copy_incoming_a7 (operands[1]); /* During reload we don't want to emit (subreg:X (mem:Y)) since that instruction won't be recognized after reload, so we remove the subreg and adjust mem accordingly. */ if (reload_in_progress) { operands[0] = fixup_subreg_mem (operands[0]); operands[1] = fixup_subreg_mem (operands[1]); } return 0;}static rtxfixup_subreg_mem (rtx x){ if (GET_CODE (x) == SUBREG && GET_CODE (SUBREG_REG (x)) == REG && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER) { rtx temp = gen_rtx_SUBREG (GET_MODE (x), reg_equiv_mem [REGNO (SUBREG_REG (x))], SUBREG_BYTE (x)); x = alter_subreg (&temp); } return x;}/* Check if an incoming argument in a7 is expected to be used soon and if OPND is a register or register pair that includes a7. If so, create a new pseudo and copy a7 into that pseudo at the very beginning of the function, followed by the special "set_frame_ptr" unspec_volatile insn. The return value is either the original operand, if it is not a7, or the new pseudo containing a copy of the incoming argument. This is necessary because the register allocator will ignore conflicts with a7 and may either assign some other pseudo to a7 or use a7 as the hard_frame_pointer, clobbering the incoming argument in a7. By copying the argument out of a7 as the very first thing, and then immediately following that with an unspec_volatile to keep the scheduler away, we should avoid any problems. Putting the set_frame_ptr insn at the beginning, with only the a7 copy before it, also makes it easier for the prologue expander to initialize the frame pointer after the a7 copy and to fix up the a7 copy to use the stack pointer instead of the frame pointer. */rtxxtensa_copy_incoming_a7 (rtx opnd){ rtx entry_insns = 0; rtx reg, tmp; enum machine_mode mode; if (!cfun->machine->need_a7_copy) return opnd; /* This function should never be called again once a7 has been copied. */ if (cfun->machine->set_frame_ptr_insn) abort (); mode = GET_MODE (opnd); /* The operand using a7 may come in a later instruction, so just return the original operand if it doesn't use a7. */ reg = opnd; if (GET_CODE (reg) == SUBREG) { if (SUBREG_BYTE (reg) != 0) abort (); reg = SUBREG_REG (reg); } if (GET_CODE (reg) != REG || REGNO (reg) > A7_REG || REGNO (reg) + HARD_REGNO_NREGS (A7_REG, mode) <= A7_REG) return opnd; /* 1-word args will always be in a7; 2-word args in a6/a7. */ if (REGNO (reg) + HARD_REGNO_NREGS (A7_REG, mode) - 1 != A7_REG) abort (); cfun->machine->need_a7_copy = false; /* Copy a7 to a new pseudo at the function entry. Use gen_raw_REG to create the REG for a7 so that hard_frame_pointer_rtx is not used. */ push_to_sequence (entry_insns); tmp = gen_reg_rtx (mode); switch (mode) { case DFmode: case DImode: emit_insn (gen_movsi_internal (gen_rtx_SUBREG (SImode, tmp, 0), gen_rtx_REG (SImode, A7_REG - 1))); emit_insn (gen_movsi_internal (gen_rtx_SUBREG (SImode, tmp, 4), gen_raw_REG (SImode, A7_REG))); break; case SFmode: emit_insn (gen_movsf_internal (tmp, gen_raw_REG (mode, A7_REG))); break; case SImode: emit_insn (gen_movsi_internal (tmp, gen_raw_REG (mode, A7_REG))); break; case HImode: emit_insn (gen_movhi_internal (tmp, gen_raw_REG (mode, A7_REG))); break; case QImode: emit_insn (gen_movqi_internal (tmp, gen_raw_REG (mode, A7_REG))); break; default: abort (); } cfun->machine->set_frame_ptr_insn = emit_insn (gen_set_frame_ptr ()); entry_insns = get_insns (); end_sequence (); if (cfun->machine->vararg_a7) { /* This is called from within builtin_savereg, so we're already inside a start_sequence that will be placed at the start of the function. */ emit_insn (entry_insns); } else { /* Put entry_insns after the NOTE that starts the function. If this is inside a start_sequence, make the outer-level insn chain current, so the code is placed at the start of the function. */ push_topmost_sequence (); emit_insn_after (entry_insns, get_insns ()); pop_topmost_sequence (); } return tmp;}/* Try to expand a block move operation to a sequence of RTL move instructions. If not optimizing, or if the block size is not a constant, or if the block is too large, the expansion fails and GCC falls back to calling memcpy(). operands[0] is the destination operands[1] is the source operands[2] is the length operands[3] is the alignment */intxtensa_expand_block_move (rtx *operands){ static const enum machine_mode mode_from_align[] = { VOIDmode, QImode, HImode, VOIDmode, SImode, }; rtx dst_mem = operands[0]; rtx src_mem = operands[1]; HOST_WIDE_INT bytes, align; int num_pieces, move_ratio; rtx temp[2]; enum machine_mode mode[2]; int amount[2]; bool active[2]; int phase = 0; int next; int offset_ld = 0; int offset_st = 0; rtx x; /* If this is not a fixed size move, just call memcpy. */ if (!optimize || (GET_CODE (operands[2]) != CONST_INT)) return 0; bytes = INTVAL (operands[2]); align = INTVAL (operands[3]); /* Anything to move? */ if (bytes <= 0) return 0; if (align > MOVE_MAX) align = MOVE_MAX; /* Decide whether to expand inline based on the optimization level. */ move_ratio = 4; if (optimize > 2) move_ratio = LARGEST_MOVE_RATIO; num_pieces = (bytes / align) + (bytes % align); /* Close enough anyway. */ if (num_pieces > move_ratio) return 0; x = XEXP (dst_mem, 0); if (!REG_P (x)) { x = force_reg (Pmode, x); dst_mem = replace_equiv_address (dst_mem, x); } x = XEXP (src_mem, 0); if (!REG_P (x)) { x = force_reg (Pmode, x); src_mem = replace_equiv_address (src_mem, x); } active[0] = active[1] = false; do { next = phase; phase ^= 1; if (bytes > 0) { int next_amount; next_amount = (bytes >= 4 ? 4 : (bytes >= 2 ? 2 : 1)); next_amount = MIN (next_amount, align); amount[next] = next_amount; mode[next] = mode_from_align[next_amount]; temp[next] = gen_reg_rtx (mode[next]); x = adjust_address (src_mem, mode[next], offset_ld); emit_insn (gen_rtx_SET (VOIDmode, temp[next], x)); offset_ld += next_amount; bytes -= next_amount; active[next] = true; } if (active[phase]) { active[phase] = false; x = adjust_address (dst_mem, mode[phase], offset_st);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -