⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arm.c

📁 Mac OS X 10.4.9 for x86 Source Code gcc 实现源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
  /* Check it against the list of known arguments.  */  for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)    if (streq (arg, ptr->arg))      return ptr->return_value;  /* An unrecognized interrupt type.  */  return ARM_FT_UNKNOWN;}/* Computes the type of the current function.  */static unsigned longarm_compute_func_type (void){  unsigned long type = ARM_FT_UNKNOWN;  tree a;  tree attr;  if (TREE_CODE (current_function_decl) != FUNCTION_DECL)    abort ();  /* Decide if the current function is volatile.  Such functions     never return, and many memory cycles can be saved by not storing     register values that will never be needed again.  This optimization     was added to speed up context switching in a kernel application.  */  if (optimize > 0      && TREE_NOTHROW (current_function_decl)      && TREE_THIS_VOLATILE (current_function_decl))    type |= ARM_FT_VOLATILE;  if (cfun->static_chain_decl != NULL)    type |= ARM_FT_NESTED;  attr = DECL_ATTRIBUTES (current_function_decl);  a = lookup_attribute ("naked", attr);  if (a != NULL_TREE)    type |= ARM_FT_NAKED;  a = lookup_attribute ("isr", attr);  if (a == NULL_TREE)    a = lookup_attribute ("interrupt", attr);  if (a == NULL_TREE)    type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL;  else    type |= arm_isr_value (TREE_VALUE (a));  return type;}/* Returns the type of the current function.  */unsigned longarm_current_func_type (void){  if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN)    cfun->machine->func_type = arm_compute_func_type ();  return cfun->machine->func_type;}/* Return 1 if it is possible to return using a single instruction.   If SIBLING is non-null, this is a test for a return before a sibling   call.  SIBLING is the call insn, so we can examine its register usage.  */intuse_return_insn (int iscond, rtx sibling){  int regno;  unsigned int func_type;  unsigned long saved_int_regs;  unsigned HOST_WIDE_INT stack_adjust;  arm_stack_offsets *offsets;  /* Never use a return instruction before reload has run.  */  if (!reload_completed)    return 0;  func_type = arm_current_func_type ();  /* Naked functions and volatile functions need special     consideration.  */  if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED))    return 0;  /* So do interrupt functions that use the frame pointer.  */  if (IS_INTERRUPT (func_type) && frame_pointer_needed)    return 0;  offsets = arm_get_frame_offsets ();  stack_adjust = offsets->outgoing_args - offsets->saved_regs;  /* As do variadic functions.  */  if (current_function_pretend_args_size      || cfun->machine->uses_anonymous_args      /* Or if the function calls __builtin_eh_return () */      || current_function_calls_eh_return      /* Or if the function calls alloca */      || current_function_calls_alloca      /* Or if there is a stack adjustment.  However, if the stack pointer	 is saved on the stack, we can use a pre-incrementing stack load.  */      || !(stack_adjust == 0 || (frame_pointer_needed && stack_adjust == 4)))    return 0;  saved_int_regs = arm_compute_save_reg_mask ();  /* Unfortunately, the insn       ldmib sp, {..., sp, ...}     triggers a bug on most SA-110 based devices, such that the stack     pointer won't be correctly restored if the instruction takes a     page fault.  We work around this problem by popping r3 along with     the other registers, since that is never slower than executing     another instruction.     We test for !arm_arch5 here, because code for any architecture     less than this could potentially be run on one of the buggy     chips.  */  if (stack_adjust == 4 && !arm_arch5)    {      /* Validate that r3 is a call-clobbered register (always true in	 the default abi) ...  */      if (!call_used_regs[3])	return 0;      /* ... that it isn't being used for a return value (always true	 until we implement return-in-regs), or for a tail-call	 argument ...  */      if (sibling)	{	  if (GET_CODE (sibling) != CALL_INSN)	    abort ();	  if (find_regno_fusage (sibling, USE, 3))	    return 0;	}      /* ... and that there are no call-saved registers in r0-r2	 (always true in the default ABI).  */      if (saved_int_regs & 0x7)	return 0;    }  /* Can't be done if interworking with Thumb, and any registers have been     stacked.  */  if (TARGET_INTERWORK && saved_int_regs != 0)    return 0;  /* On StrongARM, conditional returns are expensive if they aren't     taken and multiple registers have been stacked.  */  if (iscond && arm_is_strong)    {      /* Conditional return when just the LR is stored is a simple	 conditional-load instruction, that's not expensive.  */      if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM))	return 0;      if (flag_pic && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])	return 0;    }  /* If there are saved registers but the LR isn't saved, then we need     two instructions for the return.  */  if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM)))    return 0;  /* Can't be done if any of the FPA regs are pushed,     since this also requires an insn.  */  if (TARGET_HARD_FLOAT && TARGET_FPA)    for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++)      if (regs_ever_live[regno] && !call_used_regs[regno])	return 0;  /* Likewise VFP regs.  */  if (TARGET_HARD_FLOAT && TARGET_VFP)    for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++)      if (regs_ever_live[regno] && !call_used_regs[regno])	return 0;  if (TARGET_REALLY_IWMMXT)    for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++)      if (regs_ever_live[regno] && ! call_used_regs [regno])	return 0;  return 1;}/* Return TRUE if int I is a valid immediate ARM constant.  */intconst_ok_for_arm (HOST_WIDE_INT i){  unsigned HOST_WIDE_INT mask = ~(unsigned HOST_WIDE_INT)0xFF;  /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must     be all zero, or all one.  */  if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0      && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)	  != ((~(unsigned HOST_WIDE_INT) 0)	      & ~(unsigned HOST_WIDE_INT) 0xffffffff)))    return FALSE;  /* Fast return for 0 and powers of 2 */  if ((i & (i - 1)) == 0)    return TRUE;  do    {      if ((i & mask & (unsigned HOST_WIDE_INT) 0xffffffff) == 0)        return TRUE;      mask =	  (mask << 2) | ((mask & (unsigned HOST_WIDE_INT) 0xffffffff)			  >> (32 - 2)) | ~(unsigned HOST_WIDE_INT) 0xffffffff;    }  while (mask != ~(unsigned HOST_WIDE_INT) 0xFF);  return FALSE;}/* Return true if I is a valid constant for the operation CODE.  */static intconst_ok_for_op (HOST_WIDE_INT i, enum rtx_code code){  if (const_ok_for_arm (i))    return 1;  switch (code)    {    case PLUS:      return const_ok_for_arm (ARM_SIGN_EXTEND (-i));    case MINUS:		/* Should only occur with (MINUS I reg) => rsb */    case XOR:    case IOR:      return 0;    case AND:      return const_ok_for_arm (ARM_SIGN_EXTEND (~i));    default:      abort ();    }}/* Emit a sequence of insns to handle a large constant.   CODE is the code of the operation required, it can be any of SET, PLUS,   IOR, AND, XOR, MINUS;   MODE is the mode in which the operation is being performed;   VAL is the integer to operate on;   SOURCE is the other operand (a register, or a null-pointer for SET);   SUBTARGETS means it is safe to create scratch registers if that will   either produce a simpler sequence, or we will want to cse the values.   Return value is the number of insns emitted.  */intarm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn,		    HOST_WIDE_INT val, rtx target, rtx source, int subtargets){  rtx cond;  if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC)    cond = COND_EXEC_TEST (PATTERN (insn));  else    cond = NULL_RTX;  if (subtargets || code == SET      || (GET_CODE (target) == REG && GET_CODE (source) == REG	  && REGNO (target) != REGNO (source)))    {      /* After arm_reorg has been called, we can't fix up expensive	 constants by pushing them into memory so we must synthesize	 them in-line, regardless of the cost.  This is only likely to	 be more costly on chips that have load delay slots and we are	 compiling without running the scheduler (so no splitting	 occurred before the final instruction emission).	 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c      */      if (!after_arm_reorg	  && !cond	  && (arm_gen_constant (code, mode, NULL_RTX, val, target, source,				1, 0)	      > arm_constant_limit + (code != SET)))	{	  if (code == SET)	    {	      /* Currently SET is the only monadic value for CODE, all		 the rest are diadic.  */	      emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (val)));	      return 1;	    }	  else	    {	      rtx temp = subtargets ? gen_reg_rtx (mode) : target;	      emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (val)));	      /* For MINUS, the value is subtracted from, since we never		 have subtraction of a constant.  */	      if (code == MINUS)		emit_insn (gen_rtx_SET (VOIDmode, target,					gen_rtx_MINUS (mode, temp, source)));	      else		emit_insn (gen_rtx_SET (VOIDmode, target,					gen_rtx_fmt_ee (code, mode, source, temp)));	      return 2;	    }	}    }  return arm_gen_constant (code, mode, cond, val, target, source, subtargets,			   1);}static intcount_insns_for_constant (HOST_WIDE_INT remainder, int i){  HOST_WIDE_INT temp1;  int num_insns = 0;  do    {      int end;      if (i <= 0)	i += 32;      if (remainder & (3 << (i - 2)))	{	  end = i - 8;	  if (end < 0)	    end += 32;	  temp1 = remainder & ((0x0ff << end)				    | ((i < end) ? (0xff >> (32 - end)) : 0));	  remainder &= ~temp1;	  num_insns++;	  i -= 6;	}      i -= 2;    } while (remainder);  return num_insns;}/* Emit an instruction with the indicated PATTERN.  If COND is   non-NULL, conditionalize the execution of the instruction on COND   being true.  */static voidemit_constant_insn (rtx cond, rtx pattern){  if (cond)    pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern);  emit_insn (pattern);}/* As above, but extra parameter GENERATE which, if clear, suppresses   RTL generation.  */static intarm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond,		  HOST_WIDE_INT val, rtx target, rtx source, int subtargets,		  int generate){  int can_invert = 0;  int can_negate = 0;  int can_negate_initial = 0;  int can_shift = 0;  int i;  int num_bits_set = 0;  int set_sign_bit_copies = 0;  int clear_sign_bit_copies = 0;  int clear_zero_bit_copies = 0;  int set_zero_bit_copies = 0;  int insns = 0;  unsigned HOST_WIDE_INT temp1, temp2;  unsigned HOST_WIDE_INT remainder = val & 0xffffffff;  /* Find out which operations are safe for a given CODE.  Also do a quick     check for degenerate cases; these can occur when DImode operations     are split.  */  switch (code)    {    case SET:      can_invert = 1;      can_shift = 1;      can_negate = 1;      break;    case PLUS:      can_negate = 1;      can_negate_initial = 1;      break;    case IOR:      if (remainder == 0xffffffff)	{	  if (generate)	    emit_constant_insn (cond,				gen_rtx_SET (VOIDmode, target,					     GEN_INT (ARM_SIGN_EXTEND (val))));	  return 1;	}      if (remainder == 0)	{	  if (reload_completed && rtx_equal_p (target, source))	    return 0;	  if (generate)	    emit_constant_insn (cond,				gen_rtx_SET (VOIDmode, target, source));	  return 1;	}      break;    case AND:      if (remainder == 0)	{	  if (generate)	    emit_constant_insn (cond,				gen_rtx_SET (VOIDmode, target, const0_rtx));	  return 1;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -