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

📄 romp.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
	}      else	output_addr_const (file, x);      break;    default:      output_operand_lossage ("invalid %%xn code");    }}/* This page contains routines that are used to determine what the function   prologue and epilogue code will do and write them out.  *//*  Return the first register that is required to be saved. 16 if none.  */intfirst_reg_to_save(){  int first_reg;  /* Find lowest numbered live register.  */  for (first_reg = 6; first_reg <= 15; first_reg++)    if (regs_ever_live[first_reg])      break;  /* If we think that we do not have to save r14, see if it will be used     to be sure.  */  if (first_reg > 14 && romp_using_r14 ())    first_reg = 14;  return first_reg;}/* Compute the size of the save area in the stack, including the space for   the first four incoming arguments.  */intromp_sa_size (){  int size;  int i;  /* We have the 4 words corresponding to the arguments passed in registers,     4 reserved words, space for static chain, general register save area,     and floating-point save area.  */  size = 4 + 4 + 1 + (16 - first_reg_to_save ());  /* The documentation says we have to leave 18 words in the save area if     any floating-point registers at all are saved, not the three words     per register you might otherwise expect.  */  for (i = 2 + (TARGET_FP_REGS != 0); i <= 7; i++)    if (regs_ever_live[i + 17])      {	size += 18;	break;      }  return size * 4;}/* Return non-zero if this function makes calls or has fp operations   (which are really calls).  */intromp_makes_calls (){  rtx insn;  for (insn = get_insns (); insn; insn = next_insn (insn))    {      if (GET_CODE (insn) == CALL_INSN)	return 1;      else if (GET_CODE (insn) == INSN)	{	  rtx body = PATTERN (insn);	  if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER	      && GET_CODE (body) != ADDR_VEC	      && GET_CODE (body) != ADDR_DIFF_VEC	      && get_attr_type (insn) == TYPE_FP)	    return 1;	}    }  return 0;}/* Return non-zero if this function will use r14 as a pointer to its   constant pool.  */intromp_using_r14 (){  /* If we are debugging, profiling, have a non-empty constant pool, or     call a function, we need r14.  */  return (write_symbols != NO_DEBUG || profile_flag || get_pool_size () != 0	  || romp_makes_calls ());}/* Return non-zero if this function needs to push space on the stack.  */intromp_pushes_stack (){  /* We need to push the stack if a frame pointer is needed (because the     stack might be dynamically adjusted), if we are debugging, if the     total required size is more than 100 bytes, or if we make calls.  */  return (frame_pointer_needed || write_symbols != NO_DEBUG	  || (romp_sa_size () + get_frame_size ()) > 100	  || romp_makes_calls ());}/* Write function prologue.   We compute the size of the fixed area required as follows:   We always allocate 4 words for incoming arguments, 4 word reserved, 1   word for static link, as many words as required for general register   save area, plus 2 words for each FP reg 2-7 that must be saved.  */voidoutput_prolog (file, size)     FILE *file;     int size;{  int first_reg;  int reg_save_offset;  rtx insn;  int fp_save = size + current_function_outgoing_args_size;  init_fpops ();  /* Add in fixed size plus output argument area.  */  size += romp_sa_size () + current_function_outgoing_args_size;  /* Compute first register to save and perform the save operation if anything     needs to be saved.  */  first_reg = first_reg_to_save();  reg_save_offset = - (4 + 4 + 1 + (16 - first_reg)) * 4;  if (first_reg == 15)    fprintf (file, "\tst r15,%d(r1)\n", reg_save_offset);  else if (first_reg < 16)    fprintf (file, "\tstm r%d,%d(r1)\n", first_reg, reg_save_offset);  /* Set up pointer to data area if it is needed.  */  if (romp_using_r14 ())    fprintf (file, "\tcas r14,r0,r0\n");  /* Set up frame pointer if needed.  */  if (frame_pointer_needed)    fprintf (file, "\tcal r13,-%d(r1)\n", romp_sa_size () + 64);  /* Push stack if neeeded.  There are a couple of ways of doing this.  */  if (romp_pushes_stack ())    {      if (size >= 32768)	{	  if (size >= 65536)	    {	      fprintf (file, "\tcau r0,%d(r0)\n", size >> 16);	      fprintf (file, "\toil r0,r0,%d\n", size & 0xffff);	    }	  else	    fprintf (file, "\tcal16 r0,%d(r0)\n", size);	  fprintf (file, "\ts r1,r0\n");	}      else	fprintf (file, "\tcal r1,-%d(r1)\n", size);    }  /* Save floating-point registers.  */  output_loadsave_fpregs (file, USE,			  plus_constant (stack_pointer_rtx, fp_save));}/* Write function epilogue.  */voidoutput_epilog (file, size)     FILE *file;     int size;{  int first_reg = first_reg_to_save();  int pushes_stack = romp_pushes_stack ();  int reg_save_offset = - ((16 - first_reg) + 1 + 4 + 4) * 4;  int total_size = (size + romp_sa_size ()		    + current_function_outgoing_args_size);  int fp_save = size + current_function_outgoing_args_size;  int long_frame = total_size >= 32768;  rtx insn = get_last_insn ();  int write_code = 1;  int nargs = 0;		/* words of arguments */  tree argptr;  for (argptr = DECL_ARGUMENTS (current_function_decl);       argptr; argptr = TREE_CHAIN (argptr))    nargs += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (argptr)))	       + BITS_PER_WORD - 1) / BITS_PER_WORD);    /* If the last insn was a BARRIER, we don't have to write anything except     the trace table.  */  if (GET_CODE (insn) == NOTE)    insn = prev_nonnote_insn (insn);  if (insn && GET_CODE (insn) == BARRIER)    write_code = 0;  /* Restore floating-point registers.  */  if (write_code)    output_loadsave_fpregs (file, CLOBBER,			    gen_rtx (PLUS, Pmode, gen_rtx (REG, Pmode, 1),				     gen_rtx (CONST_INT, VOIDmode, fp_save)));  /* If we push the stack and do not have size > 32K, adjust the register     save location to the current position of sp.  Otherwise, if long frame,     restore sp from fp.  */  if (pushes_stack && ! long_frame)    reg_save_offset += total_size;  else if (long_frame && write_code)    fprintf (file, "\tcal r1,%d(r13)\n", romp_sa_size () + 64);  /* Restore registers.  */  if (first_reg == 15 && write_code)    fprintf (file, "\tl r15,%d(r1)\n", reg_save_offset);  else if (first_reg < 16 && write_code)    fprintf (file, "\tlm r%d,%d(r1)\n", first_reg, reg_save_offset);  if (first_reg == 16) first_reg = 0;  /* Handle popping stack, if needed and write debug table entry.  */  if (pushes_stack)    {      if (write_code)	{	  if (long_frame)	    fprintf (file, "\tbr r15\n");	  else	    fprintf (file, "\tbrx r15\n\tcal r1,%d(r1)\n", total_size);	}      fprintf (file, "\t.long 0x%x\n", 0xdf07df08 + first_reg * 0x10);      if (nargs > 15) nargs = 15;      if (frame_pointer_needed)	fprintf (file, "\t.byte 0x%xd, 53\n", nargs);      else	fprintf (file, "\t.short 0x%x100\n", nargs);    }  else    {      if (write_code)	fprintf (file, "\tbr r15\n");      fprintf (file, "\t.long 0xdf02df00\n");    }  /* Output any pending floating-point operations.  */  output_fpops (file);}/* For the ROMP we need to make new SYMBOL_REFs for the actual name of a   called routine.  To keep them unique we maintain a hash table of all   that have been created so far.  */struct symref_hashent {  rtx symref;			/* Created SYMBOL_REF rtx.  */  struct symref_hashent *next;	/* Next with same hash code.  */};#define SYMHASHSIZE 151#define HASHBITS 65535/* Define the hash table itself.  */static struct symref_hashent *symref_hash_table[SYMHASHSIZE];/* Given a name (allocatable in temporary storage), return a SYMBOL_REF   for the name.  The rtx is allocated from the current rtl_obstack, while   the name string is allocated from the permanent obstack.  */rtxget_symref (name)     register char *name;{  extern struct obstack permanent_obstack;  register char *sp = name;  unsigned int hash = 0;  struct symref_hashent *p, **last_p;  /* Compute the hash code for the string.  */  while (*sp)    hash = (hash << 4) + *sp++;  /* Search for a matching entry in the hash table, keeping track of the     insertion location as we do so.  */  hash = (hash & HASHBITS) % SYMHASHSIZE;  for (last_p = &symref_hash_table[hash], p = *last_p;       p; last_p = &p->next, p = *last_p)    if (strcmp (name, XSTR (p->symref, 0)) == 0)      break;  /* If couldn't find matching SYMBOL_REF, make a new one.  */  if (p == 0)    {      /* Ensure SYMBOL_REF will stay around.  */      end_temporary_allocation ();      p = *last_p = (struct symref_hashent *)			permalloc (sizeof (struct symref_hashent));      p->symref = gen_rtx (SYMBOL_REF, Pmode,			   obstack_copy0 (&permanent_obstack,					  name, strlen (name)));      p->next = 0;      resume_temporary_allocation ();    }  return p->symref;}/* Validate the precision of a floating-point operation.   We merge conversions from integers and between floating-point modes into   the insn.  However, this must not effect the desired precision of the   insn.  The RT floating-point system uses the widest of the operand modes.   If this should be a double-precision insn, ensure that one operand   passed to the floating-point processor has double mode.   Note that since we don't check anything if the mode is single precision,   it, strictly speaking, isn't necessary to call this for those insns.   However, we do so in case something else needs to be checked in the   future.   This routine returns 1 if the operation is OK.  */intcheck_precision (opmode, op1, op2)     enum machine_mode opmode;     rtx op1, op2;{  if (opmode == SFmode)    return 1;  /* If operand is not a conversion from an integer mode or an extension from     single-precision, it must be a double-precision value.  */  if (GET_CODE (op1) != FLOAT && GET_CODE (op1) != FLOAT_EXTEND)    return 1;  if (op2 && GET_CODE (op2) != FLOAT && GET_CODE (op2) != FLOAT_EXTEND)    return 1;  return 0;}/* Floating-point on the RT is done by creating an operation block in the data   area that describes the operation.  If two floating-point operations are the   same in a single function, they can use the same block.   These routines are responsible for managing these blocks.  *//* Structure to describe a floating-point operation.  */struct fp_op {  struct fp_op *next_same_hash;		/* Next op with same hash code. */  struct fp_op *next_in_mem;		/* Next op in memory. */  int mem_offset;			/* Offset from data area.  */  short size;				/* Size of block in bytes.  */  short noperands;			/* Number of operands in block.  */  rtx ops[3];				/* RTL for operands. */  enum rtx_code opcode;			/* Operation being performed.  */};/* Size of hash table.  */#define FP_HASH_SIZE 101/* Hash table of floating-point operation blocks.  */static struct fp_op *fp_hash_table[FP_HASH_SIZE];/* First floating-point block in data area.  */static struct fp_op *first_fpop;/* Last block in data area so far.  */static struct fp_op *last_fpop_in_mem;/* Subroutine number in file, to get unique "LF" labels.  */static int subr_number = 0;/* Current word offset in data area (includes header and any constant pool). */int data_offset;/* Compute hash code for an RTX used in floating-point.  */static unsigned inthash_rtx (x)     register rtx x;{  register unsigned int hash = (((int) GET_CODE (x) << 10)				+ ((int) GET_MODE (x) << 20));  register int i;  register char *fmt = GET_RTX_FORMAT (GET_CODE (x));  for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)    if (fmt[i] == 'e')      hash += hash_rtx (XEXP (x, i));    else if (fmt[i] == 'u')      hash += (int) XEXP (x, i);    else if (fmt[i] == 'i')      hash += XINT (x, i);    else if (fmt[i] == 's')      hash += (int) XSTR (x, i);  return hash;}/* Given an operation code and up to three operands, return a character string   corresponding to the code to emit to branch to a floating-point operation   block.  INSN is provided to see if the delay slot has been filled or not.   A new floating-point operation block is created if this operation has not   been seen before.  */char *output_fpop (code, op0, op1, op2, insn)     enum rtx_code code;     rtx op0, op1, op2;     rtx insn;{  static char outbuf[40];  unsigned int hash, hash0, hash1, hash2;  int size, i;  register struct fp_op *fpop, *last_fpop;  int dyadic = (op2 != 0);  enum machine_mode opmode;  int noperands;  rtx tem;  unsigned int tem_hash;  int fr0_avail = 0;  /* Compute hash code for each operand.  If the operation is commutative,     put the one with the smaller hash code first.  This will make us see     more operations as identical.  */  hash0 = op0 ? hash_rtx (op0) : 0;  hash1 = op1 ? hash_rtx (op1) : 0;  hash2 = op2 ? hash_rtx (op2) : 0;  if (hash0 > hash1 && code == EQ)    {      tem = op0; op0 = op1; op1 = tem;      tem_hash = hash0; hash0 = hash1; hash1 = tem_hash;    }  else if (hash1 > hash2 && (code == PLUS || code == MULT))    {      tem = op1; op1 = op2; op2 = tem;      tem_hash = hash1; hash1 = hash2; hash2 = tem_hash;    }  /* If operation is commutative and the first and third operands are equal,     swap the second and third operands.  Note that we must consider two     operands equal if they are the same register even if different modes.  */  if (op2 && (code == PLUS || code == MULT)      && (rtx_equal_p (op0, op2)	  || (GET_CODE (op0) == REG && GET_CODE (op2) == REG	      && REGNO (op0) == REGNO (op2))))    {      tem = op1; op1 = op2; op2 = tem;      tem_hash = hash1; hash1 = hash2; hash2 = tem_hash;    }  /* If the first and second operands are the same, merge them.  Don't do this     for SFmode or SImode in general registers because this triggers a bug in     the RT fp code.  */  if (op1 && rtx_equal_p (op0, op1)      && code != EQ && code != GE && code != SET      && ((GET_MODE (op1) != SFmode && GET_MODE (op1) != SImode)	  || GET_CODE (op0) != REG || FP_REGNO_P (REGNO (op0))))    {      op1 = op2;      op2 = 0;    }

⌨️ 快捷键说明

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