📄 optabs.c
字号:
} if (targ0) targ0 = protect_from_queue (targ0, 1); else targ0 = gen_reg_rtx (mode); if (targ1) targ1 = protect_from_queue (targ1, 1); else targ1 = gen_reg_rtx (mode); if (binoptab->handlers[(int) mode].insn_code != CODE_FOR_nothing) { emit_insn (GEN_FCN (binoptab->handlers[(int) mode].insn_code) (targ0, op0, op1, targ1)); return 1; } /* It can't be done in this mode. Can we do it in a wider mode? */ if (class == MODE_INT || class == MODE_FLOAT) { for (wider_mode = INC_MODE (mode); ((int) wider_mode < (int) MAX_MACHINE_MODE && GET_MODE_CLASS (wider_mode) == class); wider_mode = INC_MODE (wider_mode)) { if (binoptab->handlers[(int) wider_mode].insn_code != CODE_FOR_nothing) { expand_twoval_binop_convert (binoptab, wider_mode, op0, op1, targ0, targ1, unsignedp); return 1; } } } return 0;}intexpand_twoval_binop_convert (binoptab, mode, op0, op1, targ0, targ1, unsignedp) register optab binoptab; register rtx op0, op1, targ0, targ1; int unsignedp;{ register rtx t0 = gen_reg_rtx (SImode); register rtx t1 = gen_reg_rtx (SImode); register rtx temp; temp = gen_reg_rtx (SImode); convert_move (temp, op0, unsignedp); op0 = temp; temp = gen_reg_rtx (SImode); convert_move (temp, op1, unsignedp); op1 = temp; expand_twoval_binop (binoptab, op0, op1, t0, t1, unsignedp); convert_move (targ0, t0, unsignedp); convert_move (targ1, t1, unsignedp); return 1;}/* Generate code to perform an operation specified by UNOPTAB on operand OP0, with result having machine-mode MODE. UNSIGNEDP is for the case where we have to widen the operands to perform the operation. It says to use zero-extension. If TARGET is nonzero, the value is generated there, if it is convenient to do so. In all cases an rtx is returned for the locus of the value; this may or may not be TARGET. */rtxexpand_unop (mode, unoptab, op0, target, unsignedp) enum machine_mode mode; optab unoptab; rtx op0; rtx target; int unsignedp;{ enum mode_class class; enum machine_mode wider_mode; register rtx temp; class = GET_MODE_CLASS (mode); op0 = protect_from_queue (op0, 0); if (flag_force_mem) { op0 = force_not_mem (op0); } if (target) target = protect_from_queue (target, 1); if (unoptab->handlers[(int) mode].insn_code != CODE_FOR_nothing) { int icode = (int) unoptab->handlers[(int) mode].insn_code; enum machine_mode mode0 = insn_operand_mode[icode][1]; if (target) temp = target; else temp = gen_reg_rtx (mode); if (GET_MODE (op0) != VOIDmode && GET_MODE (op0) != mode0) op0 = convert_to_mode (mode0, op0, unsignedp); /* Now, if insn requires register operands, put operands into regs. */ if (! (*insn_operand_predicate[icode][1]) (op0, mode0)) op0 = force_reg (mode0, op0); if (! (*insn_operand_predicate[icode][0]) (temp, mode)) temp = gen_reg_rtx (mode); emit_insn (GEN_FCN (icode) (temp, op0)); return temp; } else if (unoptab->handlers[(int) mode].lib_call) { rtx insn_before, insn_last; rtx funexp = gen_rtx (SYMBOL_REF, Pmode, unoptab->handlers[(int) mode].lib_call); /* Pass the address through a pseudoreg, if desired, before the "beginning" of the library call (for deletion). */#ifndef NO_FUNCTION_CSE if (! flag_no_function_cse) funexp = copy_to_mode_reg (Pmode, funexp);#endif insn_before = get_last_insn (); /* Cannot pass FUNEXP since emit_library_call insists on getting a SYMBOL_REF. But cse will make this SYMBOL_REF be replaced with the copy we made just above. */ /* Pass 1 for NO_QUEUE so we don't lose any increments if the libcall is cse'd or moved. */ emit_library_call (gen_rtx (SYMBOL_REF, Pmode, unoptab->handlers[(int) mode].lib_call), 1, mode, 1, op0, mode); target = hard_libcall_value (mode); temp = copy_to_reg (target); insn_last = get_last_insn (); REG_NOTES (insn_last) = gen_rtx (EXPR_LIST, REG_EQUAL, gen_rtx (unoptab->code, mode, op0), gen_rtx (INSN_LIST, REG_RETVAL, NEXT_INSN (insn_before), REG_NOTES (insn_last))); REG_NOTES (NEXT_INSN (insn_before)) = gen_rtx (INSN_LIST, REG_LIBCALL, insn_last, REG_NOTES (NEXT_INSN (insn_before))); return temp; } /* It can't be done in this mode. Can we do it in a wider mode? */ if (class == MODE_INT || class == MODE_FLOAT) { for (wider_mode = INC_MODE (mode); ((int) wider_mode < (int) MAX_MACHINE_MODE && GET_MODE_CLASS (wider_mode) == class); wider_mode = INC_MODE (wider_mode)) { if ((unoptab->handlers[(int) wider_mode].insn_code != CODE_FOR_nothing) || unoptab->handlers[(int) wider_mode].lib_call) { if (GET_MODE (op0) != VOIDmode) { temp = gen_reg_rtx (wider_mode); convert_move (temp, op0, unsignedp); op0 = temp; } target = expand_unop (wider_mode, unoptab, op0, 0, unsignedp); if (class == MODE_FLOAT) { if (target == 0) target = gen_reg_rtx (mode); convert_move (target, temp, 0); return target; } else return gen_lowpart (mode, target); } } } return 0;}/* Generate an instruction whose insn-code is INSN_CODE, with two operands: an output TARGET and an input OP0. TARGET *must* be nonzero, and the output is always stored there. CODE is an rtx code such that (CODE OP0) is an rtx that describes the value that is stored into TARGET. */voidemit_unop_insn (icode, target, op0, code) int icode; rtx target; rtx op0; enum rtx_code code;{ register rtx temp; enum machine_mode mode0 = insn_operand_mode[icode][1]; rtx insn; rtx prev_insn; temp = target = protect_from_queue (target, 1); op0 = protect_from_queue (op0, 0); if (flag_force_mem) op0 = force_not_mem (op0); /* Now, if insn requires register operands, put operands into regs. */ if (! (*insn_operand_predicate[icode][1]) (op0, mode0)) op0 = force_reg (mode0, op0); if (! (*insn_operand_predicate[icode][0]) (temp, GET_MODE (temp)) || (flag_force_mem && GET_CODE (temp) == MEM)) temp = gen_reg_rtx (GET_MODE (temp)); prev_insn = get_last_insn (); insn = emit_insn (GEN_FCN (icode) (temp, op0)); /* If we just made a multi-insn sequence, record in the last insn an equivalent expression for its value and a pointer to the first insn. This makes cse possible. */ if (code != UNKNOWN && PREV_INSN (insn) != prev_insn) REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_EQUAL, gen_rtx (code, GET_MODE (temp), op0), REG_NOTES (insn)); if (temp != target) emit_move_insn (target, temp);}/* Generate code to store zero in X. */voidemit_clr_insn (x) rtx x;{ emit_move_insn (x, const0_rtx);}/* Generate code to store 1 in X assuming it contains zero beforehand. */voidemit_0_to_1_insn (x) rtx x;{ emit_move_insn (x, const1_rtx);}/* Generate code to compare X with Y so that the condition codes are set. UNSIGNEDP nonzero says that X and Y are unsigned; this matters if they need to be widened. If they have mode BLKmode, then SIZE specifies the size of both X and Y, and ALIGN specifies the known shared alignment of X and Y. */voidemit_cmp_insn (x, y, size, unsignedp, align) rtx x, y; rtx size; int unsignedp; int align;{ enum machine_mode mode = GET_MODE (x); enum mode_class class; enum machine_mode wider_mode; if (mode == VOIDmode) mode = GET_MODE (y); /* They could both be VOIDmode if both args are immediate constants, but we should fold that at an earlier stage. With no special code here, this will call abort, reminding the programmer to implement such folding. */ class = GET_MODE_CLASS (mode); if (mode != BLKmode && flag_force_mem) { x = force_not_mem (x); y = force_not_mem (y); } /* Handle all BLKmode compares. */ if (mode == BLKmode) { emit_queue (); x = protect_from_queue (x, 0); y = protect_from_queue (y, 0); if (size == 0) abort ();#ifdef HAVE_cmpstrqi if (HAVE_cmpstrqi && GET_CODE (size) == CONST_INT && INTVAL (size) < (1 << GET_MODE_BITSIZE (QImode))) emit_insn (gen_cmpstrqi (x, y, size, gen_rtx (CONST_INT, VOIDmode, align))); else#endif#ifdef HAVE_cmpstrhi if (HAVE_cmpstrhi && GET_CODE (size) == CONST_INT && INTVAL (size) < (1 << GET_MODE_BITSIZE (HImode))) emit_insn (gen_cmpstrhi (x, y, size, gen_rtx (CONST_INT, VOIDmode, align))); else#endif#ifdef HAVE_cmpstrsi if (HAVE_cmpstrsi) emit_insn (gen_cmpstrsi (x, y, convert_to_mode (SImode, size, 1), gen_rtx (CONST_INT, VOIDmode, align))); else#endif {#ifdef TARGET_MEM_FUNCTIONS emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "memcmp"), 0, SImode, 3, XEXP (x, 0), Pmode, XEXP (y, 0), Pmode, size, Pmode);#else emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "bcmp"), 0, SImode, 3, XEXP (x, 0), Pmode, XEXP (y, 0), Pmode, size, Pmode);#endif emit_cmp_insn (hard_libcall_value (SImode), const0_rtx, 0, 0, 0); } return; } /* Handle some compares against zero. */ if (y == CONST0_RTX (mode) && tst_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing) { int icode = (int) tst_optab->handlers[(int) mode].insn_code; emit_queue (); x = protect_from_queue (x, 0); y = protect_from_queue (y, 0); /* Now, if insn requires register operands, put operands into regs. */ if (! (*insn_operand_predicate[icode][0]) (x, insn_operand_mode[icode][0])) x = force_reg (insn_operand_mode[icode][0], x); emit_insn (GEN_FCN (icode) (x)); return; } /* Handle compares for which there is a directly suitable insn. */ if (cmp_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing) { int icode = (int) cmp_optab->handlers[(int) mode].insn_code; emit_queue (); x = protect_from_queue (x, 0); y = protect_from_queue (y, 0); /* Now, if insn requires register operands, put operands into regs. */ if (! (*insn_operand_predicate[icode][0]) (x, insn_operand_mode[icode][0])) x = force_reg (insn_operand_mode[icode][0], x); if (! (*insn_operand_predicate[icode][1]) (y, insn_operand_mode[icode][1])) y = force_reg (insn_operand_mode[icode][1], y); emit_insn (GEN_FCN (icode) (x, y)); return; } /* Try widening if we can find a direct insn that way. */ if (class == MODE_INT || class == MODE_FLOAT) { for (wider_mode = INC_MODE (mode); ((int) wider_mode < (int) MAX_MACHINE_MODE && GET_MODE_CLASS (wider_mode) == class); wider_mode = INC_MODE (wider_mode)) { if (cmp_optab->handlers[(int) wider_mode].insn_code != CODE_FOR_nothing) { x = convert_to_mode (wider_mode, x, unsignedp); y = convert_to_mode (wider_mode, y, unsignedp); emit_cmp_insn (x, y, 0, unsignedp, align); return; } } } /* Handle a lib call just for the mode we are using. */ if (cmp_optab->handlers[(int) mode].lib_call) { char *string = cmp_optab->handlers[(int) mode].lib_call; /* If we want unsigned, and this mode has a distinct unsigned comparison routine, use that. */ if (unsignedp && ucmp_optab->handlers[(int) mode].lib_call) string = ucmp_optab->handlers[(int) mode].lib_call; emit_library_call (gen_rtx (SYMBOL_REF, Pmode, string), 0, SImode, 2, x, mode, y, mode); /* Integer comparison returns a result that must be compared against 1, so that even if we do an unsigned compare afterward, there is still a value that can represent the result "less than". */ if (GET_MODE_CLASS (mode) == MODE_INT) emit_cmp_insn (hard_libcall_value (SImode), const1_rtx, 0, unsignedp, 0); else emit_cmp_insn (hard_libcall_value (SImode), const0_rtx, 0, 0, 0); return; } /* Try widening and then using a libcall. */ if (class == MODE_FLOAT) { for (wider_mode = INC_MODE (mode); ((int) wider_mode < (int) MAX_MACHINE_MODE && GET_MODE_CLASS (wider_mode) == class); wider_mode = INC_MODE (wider_mode)) { if ((cmp_optab->handlers[(int) wider_mode].insn_code != CODE_FOR_nothing) || (cmp_optab->handlers[(int) wider_mode].lib_call != 0))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -