📄 mn10200.c
字号:
/* We need to end the current sequence so that count_tst_insns can look at all the insns in this function. Normally this would be unsafe, but it's OK in the prologue/epilogue expanders. */ end_sequence (); /* Get a count of the number of tst insns which use address registers (it's not profitable to try and improve tst insns which use data registers). */ count_tst_insns (&areg_count); /* Now start a new sequence. */ start_sequence (); /* Compute how many bytes an inline prologue would take. Each address register store takes two bytes, each data register store takes three bytes. */ inline_count = 0; if (regs_ever_live[5]) inline_count += 2; if (regs_ever_live[6]) inline_count += 2; if (regs_ever_live[2]) inline_count += 3; if (regs_ever_live[3]) inline_count += 3; /* If this function has any stack, then the stack adjustment will take two (or more) bytes. */ if (size || outgoing_args_size || regs_ever_live[5] || regs_ever_live[6] || regs_ever_live[2] || regs_ever_live[3]) inline_count += 2; /* Multiply the current count by two and add one to account for the epilogue insns. */ inline_count = inline_count * 2 + 1; /* Now compute how many bytes an out of line sequence would take. */ /* A relaxed jsr will be three bytes. */ outline_count = 3; /* If there are outgoing arguments, then we will need a stack pointer adjustment after the call to the prologue, two more bytes. */ outline_count += (outgoing_args_size == 0 ? 0 : 2); /* If there is some local frame to allocate, it will need to be done before the call to the prologue, two more bytes. */ if (get_frame_size () != 0) outline_count += 2; /* Now account for the epilogue, multiply the base count by two, then deal with optimizing away the rts instruction. */ outline_count = outline_count * 2 + 1; if (get_frame_size () == 0 && outgoing_args_size == 0) outline_count -= 1; /* If an out of line prologue is smaller, use it. */ if (inline_count > outline_count) { if (get_frame_size () != 0) emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-size + outgoing_args_size + 16))); emit_insn (gen_outline_prologue_call ()); if (outgoing_args_size) emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-outgoing_args_size))); out_of_line_epilogue = 1; /* Determine if it is profitable to put the value zero into a register for the entire function. If so, set ZERO_DREG and ZERO_AREG. */ /* First see if we could load the value into a data register since that's the most efficient way. */ if (areg_count > 1 && (!regs_ever_live[2] || !regs_ever_live[3])) { if (!regs_ever_live[2]) { regs_ever_live[2] = 1; zero_dreg = gen_rtx (REG, HImode, 2); } if (!regs_ever_live[3]) { regs_ever_live[3] = 1; zero_dreg = gen_rtx (REG, HImode, 3); } } /* Now see if we could load the value into a address register. */ if (zero_dreg == NULL_RTX && areg_count > 2 && (!regs_ever_live[5] || !regs_ever_live[6])) { if (!regs_ever_live[5]) { regs_ever_live[5] = 1; zero_areg = gen_rtx (REG, HImode, 5); } if (!regs_ever_live[6]) { regs_ever_live[6] = 1; zero_areg = gen_rtx (REG, HImode, 6); } } if (zero_dreg) emit_move_insn (zero_dreg, const0_rtx); if (zero_areg) emit_move_insn (zero_areg, const0_rtx); return; } } out_of_line_epilogue = 0; /* Temporarily stuff the static chain onto the stack so we can use a0 as a scratch register during the prologue. */ if (current_function_needs_context) { emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-4))); emit_move_insn (gen_rtx (MEM, PSImode, stack_pointer_rtx), gen_rtx (REG, PSImode, STATIC_CHAIN_REGNUM)); } if (frame_pointer_needed) { /* Store a2 into a0 temporarily. */ emit_move_insn (gen_rtx (REG, PSImode, 4), frame_pointer_rtx); /* Set up the frame pointer. */ emit_move_insn (frame_pointer_rtx, stack_pointer_rtx); } /* Make any necessary space for the saved registers and local frame. */ if (size) emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-size))); /* Save the callee saved registers. They're saved into the top of the frame, using the stack pointer. */ for (i = 0, offset = outgoing_args_size; i < FIRST_PSEUDO_REGISTER; i++) { if (regs_ever_live[i] && !call_used_regs[i] && ! fixed_regs[i] || (i == FRAME_POINTER_REGNUM && frame_pointer_needed)) { int regno; /* If we're saving the frame pointer, then it will be found in register 4 (a0). */ regno = (i == FRAME_POINTER_REGNUM && frame_pointer_needed) ? 4 : i; emit_move_insn (gen_rtx (MEM, PSImode, gen_rtx (PLUS, Pmode, stack_pointer_rtx, GEN_INT (offset))), gen_rtx (REG, PSImode, regno)); offset += 4; } } /* Now put the static chain back where the rest of the function expects to find it. */ if (current_function_needs_context) { emit_move_insn (gen_rtx (REG, PSImode, STATIC_CHAIN_REGNUM), gen_rtx (MEM, PSImode, gen_rtx (PLUS, PSImode, stack_pointer_rtx, GEN_INT (size)))); }}/* Expand the epilogue into RTL. */voidexpand_epilogue (){ unsigned int size; unsigned int outgoing_args_size = current_function_outgoing_args_size; int offset, i, temp_regno; rtx basereg; size = total_frame_size (); if (DECL_RESULT (current_function_decl) && DECL_RTL (DECL_RESULT (current_function_decl)) && REG_P (DECL_RTL (DECL_RESULT (current_function_decl)))) temp_regno = (REGNO (DECL_RTL (DECL_RESULT (current_function_decl))) == 4 ? 0 : 4); else temp_regno = 4; /* Emit an out of line epilogue sequence if it's profitable to do so. */ if (out_of_line_epilogue) { /* If there were no outgoing arguments and no local frame, then we will be able to omit the rts at the end of this function, so just jump to the epilogue_noreturn routine. */ if (get_frame_size () == 0 && outgoing_args_size == 0) { emit_jump_insn (gen_outline_epilogue_jump ()); return; } if (outgoing_args_size) emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (outgoing_args_size))); if (temp_regno == 0) emit_insn (gen_outline_epilogue_call_d0 ()); else if (temp_regno == 4) emit_insn (gen_outline_epilogue_call_a0 ()); if (get_frame_size () != 0) emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (size - outgoing_args_size - 16))); emit_jump_insn (gen_return_internal ()); return; } /* Registers are restored from the frame pointer if we have one, else they're restored from the stack pointer. Figure out the appropriate offset to the register save area for both cases. */ if (frame_pointer_needed) { basereg = frame_pointer_rtx; offset = -(size - outgoing_args_size); } else { basereg = stack_pointer_rtx; offset = outgoing_args_size; } /* Restore each register. */ for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) { if (regs_ever_live[i] && !call_used_regs[i] && ! fixed_regs[i] || (i == FRAME_POINTER_REGNUM && frame_pointer_needed)) { int regno; /* Restore the frame pointer (if it exists) into a temporary register. */ regno = ((i == FRAME_POINTER_REGNUM && frame_pointer_needed) ? temp_regno : i); emit_move_insn (gen_rtx (REG, PSImode, regno), gen_rtx (MEM, PSImode, gen_rtx (PLUS, Pmode, basereg, GEN_INT (offset)))); offset += 4; } } if (frame_pointer_needed) { /* Deallocate this frame's stack. */ emit_move_insn (stack_pointer_rtx, frame_pointer_rtx); /* Restore the old frame pointer. */ emit_move_insn (frame_pointer_rtx, gen_rtx (REG, PSImode, temp_regno)); } else if (size) { /* Deallocate this function's stack. */ emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (size))); } /* If we had to allocate a slot to save the context pointer, then it must be deallocated here. */ if (current_function_needs_context) emit_insn (gen_addpsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (4))); /* Emit the return insn, if this function had no stack, then we can use the standard return (which allows more optimizations), else we have to use the special one which inhibits optimizations. */ if (size == 0 && !current_function_needs_context) emit_jump_insn (gen_return ()); else emit_jump_insn (gen_return_internal ());}/* Update the condition code from the insn. */voidnotice_update_cc (body, insn) rtx body; rtx insn;{ switch (get_attr_cc (insn)) { case CC_NONE: /* Insn does not affect CC at all. */ break; case CC_NONE_0HIT: /* Insn does not change CC, but the 0'th operand has been changed. */ if (cc_status.value1 != 0 && reg_overlap_mentioned_p (recog_operand[0], cc_status.value1)) cc_status.value1 = 0; break; case CC_SET_ZN: /* Insn sets the Z,N flags of CC to recog_operand[0]. V,C is in an unusable state. */ CC_STATUS_INIT; cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY; cc_status.value1 = recog_operand[0]; break; case CC_SET_ZNV: /* Insn sets the Z,N,V flags of CC to recog_operand[0]. C is in an unusable state. */ CC_STATUS_INIT; cc_status.flags |= CC_NO_CARRY; cc_status.value1 = recog_operand[0]; break; case CC_COMPARE: /* The insn is a compare instruction. */ CC_STATUS_INIT; cc_status.value1 = SET_SRC (body); break; case CC_CLOBBER: /* Insn doesn't leave CC in a usable state. */ CC_STATUS_INIT; break; default: CC_STATUS_INIT; break; }}/* Return true if OP is a valid call operand. Valid call operands are SYMBOL_REFs and REGs. */intcall_address_operand (op, mode) rtx op; enum machine_mode mode;{ return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);}/* Return true if OP is a memory operand with a constant address. A special PSImode move pattern uses this predicate. */intconstant_memory_operand (op, mode) rtx op; enum machine_mode mode;{ return GET_CODE (op) == MEM && CONSTANT_ADDRESS_P (XEXP (op, 0));}/* What (if any) secondary registers are needed to move IN with mode MODE into a register from in register class CLASS. We might be able to simplify this. */enum reg_classsecondary_reload_class (class, mode, in, input) enum reg_class class; enum machine_mode mode; rtx in; int input;{ int regno; /* Memory loads less than a full word wide can't have an address or stack pointer destination. They must use a data register as an intermediate register. */ if (input && GET_CODE (in) == MEM && (mode == QImode) && class == ADDRESS_REGS) return DATA_REGS; /* Address register stores which are not PSImode need a scratch register. */ if (! input && GET_CODE (in) == MEM && (mode != PSImode) && class == ADDRESS_REGS) return DATA_REGS; /* Otherwise assume no secondary reloads are needed. */ return NO_REGS;}/* Shifts. We devote a fair bit of code to getting efficient shifts since we can only shift one bit at a time, and each single bit shift may take multiple instructions. The basic shift methods: * loop shifts -- emit a loop using one (or two on H8/S) bit shifts; this is the default. SHIFT_LOOP * inlined shifts -- emit straight line code for the shift; this is used when a straight line shift is about the same size or smaller than a loop. We allow the inline version to be slightly longer in some cases as it saves a register. SHIFT_INLINE * There other oddballs. Not worth explaining. SHIFT_SPECIAL HImode shifts: 1-4 do them inline 5-7 If ashift, then multiply, else loop. 8-14 - If ashift, then multiply, if lshiftrt, then divide, else loop. 15 - rotate the bit we want into the carry, clear the destination, (use mov 0,dst, not sub as sub will clobber the carry), then move bit into place. Don't Panic, it's not nearly as bad as the H8 shifting code!!! */intnshift_operator (x, mode) rtx x; enum machine_mode mode;{ switch (GET_CODE (x)) { case ASHIFTRT: case LSHIFTRT: case ASHIFT: return 1; default: return 0; }}/* Called from the .md file to emit code to do shifts. Returns a boolean indicating success (currently this is always TRUE). */intexpand_a_shift (mode, code, operands) enum machine_mode mode; int code; rtx operands[];{ emit_move_insn (operands[0], operands[1]); /* need a loop to get all the bits we want - we generate the code at emit time, but need to allocate a scratch reg now */ emit_insn (gen_rtx (PARALLEL, VOIDmode, gen_rtvec (2, gen_rtx (SET, VOIDmode, operands[0], gen_rtx (code, mode, operands[0], operands[2])), gen_rtx (CLOBBER, VOIDmode, gen_rtx (SCRATCH, HImode, 0))))); return 1;}/* Shift algorithm determination. There are various ways of doing a shift: SHIFT_INLINE: If the amount is small enough, just generate as many one-bit shifts as we need. SHIFT_SPECIAL: Hand crafted assembler. SHIFT_LOOP: If the above methods fail, just loop. */enum shift_alg{ SHIFT_INLINE, SHIFT_SPECIAL, SHIFT_LOOP, SHIFT_MAX};/* Symbols of the various shifts which can be used as indices. */enum shift_type { SHIFT_ASHIFT, SHIFT_LSHIFTRT, SHIFT_ASHIFTRT };/* Symbols of the various modes which can be used as indices. */enum shift_mode { HIshift, };/* For single bit shift insns, record assembler and what bits of the condition code are valid afterwards (represented as various CC_FOO bits, 0 means CC isn't left in a usable state). */struct shift_insn{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -