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

📄 romp.c

📁 linux下的gcc编译器
💻 C
📖 第 1 页 / 共 4 页
字号:
	  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 nonzero 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 || current_function_profile	  || get_pool_size () != 0 || romp_makes_calls ());}/* Return nonzero 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.  */static voidromp_output_function_prologue (file, size)     FILE *file;     HOST_WIDE_INT size;{  int first_reg;  int reg_save_offset;  HOST_WIDE_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));}/* Output the offset information used by debuggers.   This is the exactly the total_size value of output_function_epilogue()   which is added to the frame pointer. However the value in the debug   table is encoded in a space-saving way as follows:   The first byte contains two fields: a 2-bit size field and the first   6 bits of an offset value. The 2-bit size field is in the high-order   position and specifies how many subsequent bytes follow after   this one. An offset value is at most 4-bytes long.   The last 6 bits of the first byte initialize the offset value. In many   cases where procedures have small local storage, this is enough and, in   this case, the high-order size field is zero so the byte can (almost) be   used as is (see below). Thus, the byte value of 0x0d is encodes an offset   size of 13 words, or 52 bytes.   For procedures with a local space larger than 60 bytes, the 6 bits   are the high-order 6 bits.  The remaining bytes follow as necessary,   in Big Endian order.  Thus, the short value of 16907 (= 16384+523)   encodes an offset of 2092 bytes (523 words).   The total offset value is in words (not bytes), so the final value has to   be multiplied by 4 before it can be used in address computations by a   debugger.   */voidoutput_encoded_offset (file, reg_offset)     FILE *file;     unsigned reg_offset;{  /* Convert the offset value to 4-byte words rather than bytes.  */  reg_offset = (reg_offset + 3) / 4;  /* Now output 1-4 bytes in encoded form.  */  if (reg_offset < (1 << 6))    /* Fits into one byte */    fprintf (file, "\t.byte %d\n", reg_offset);  else if (reg_offset < (1 << (6 + 8)))    /* Fits into two bytes */    fprintf (file, "\t.short %d\n", (1 << (6 + 8)) + reg_offset);  else if (reg_offset < (1 << (6 + 8 + 8)))    {      /* Fits in three bytes */      fprintf (file, "\t.byte %d\n", (2 << 6) + (reg_offset >> ( 6+ 8)));      fprintf (file, "\t.short %d\n", reg_offset % (1 << (6 + 8)));    }  else    {      /* Use 4 bytes.  */      fprintf (file, "\t.short %d", (3 << (6 + 8)) + (reg_offset >> (6 + 8)));      fprintf (file, "\t.short %d\n", reg_offset % (1 << (6 + 8)));    }}/* Write function epilogue.  */static voidromp_output_function_epilogue (file, size)     FILE *file;     HOST_WIDE_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;  HOST_WIDE_INT total_size = (size + romp_sa_size ()			      + current_function_outgoing_args_size);  HOST_WIDE_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;  /* Compute the number of words of arguments.  Since this is just for     the traceback table, we ignore arguments that don't have a size or     don't have a fixed size.  */  for (argptr = DECL_ARGUMENTS (current_function_decl);       argptr; argptr = TREE_CHAIN (argptr))    {      int this_size = int_size_in_bytes (TREE_TYPE (argptr));      if (this_size > 0)	nargs += (this_size + UNITS_PER_WORD - 1) / UNITS_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,			    plus_constant (gen_rtx_REG (Pmode, 1), 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);	}      /* Table header (0xdf), usual-type stack frame (0x07),	 table header (0xdf), and first register saved.	 The final 0x08 means that there is a byte following this one	 describing the number of parameter words and the register used as	 stack pointer.	 If GCC passed floating-point parameters in floating-point registers,	 it would be necessary to change the final byte from 0x08 to 0x0c.	 Also an additional entry byte would be need to be emitted to specify	 the first floating-point register.	 (See also Section 11 (Trace Tables) in ``IBM/4.3 Linkage Convention,''	 pages IBM/4.3-PSD:5-7 of Volume III of the IBM Academic Operating	 System Manual dated July 1987.)  */      fprintf (file, "\t.long 0x%x\n", 0xdf07df08 + first_reg * 0x10);      if (nargs > 15) nargs = 15;      /* The number of parameter words and the register used as the stack	 pointer (encoded here as r1).	 Note: The MetWare Hich C Compiler R2.1y actually gets this wrong;	 it erroneously lists r13 but uses r1 as the stack too. But a bug in	 dbx 1.5 nullifies this mistake---most of the time.         (Dbx retrieves the value of r13 saved on the stack which is often	 the value of r1 before the call.)  */      fprintf (file, "\t.byte 0x%x1\n", nargs);      output_encoded_offset (file, total_size);    }  else    {      if (write_code)	fprintf (file, "\tbr r15\n");      /* Table header (0xdf), no stack frame (0x02),	 table header (0xdf) and no parameters saved (0x00).	 If GCC passed floating-point parameters in floating-point registers,	 it might be necessary to change the final byte from 0x00 to 0x04.	 Also a byte would be needed to specify the first floating-point	 register.  */      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 (allocable 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 const char *name;{  register const 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.  */      p = *last_p = (struct symref_hashent *)			xmalloc (sizeof (struct symref_hashent));      p->symref = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));      p->next = 0;    }  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 const 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 += (unsigned HOST_WIDE_INT) XEXP (x, i);    else if (fmt[i] == 'i')      hash += XINT (x, i);    else if (fmt[i] == 's')      hash += (unsigned HOST_WIDE_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.  */const char *output_fpop (code, op0, op1, op2, insn)     enum rtx_code code;     rtx op0, op1, op2;     rtx insn ATTRIBUTE_UNUSED;{  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;    }  noperands = 1 + (op1 != 0) + (op2 != 0);  /* Compute hash code for entire expression and see if operation block     already exists.  */  hash = ((int) code << 13) + (hash0 << 2) + (hash1 << 1) + hash2;  hash %= FP_HASH_SIZE;  for (fpop = fp_hash_table[hash], last_fpop = 0;       fpop;       last_fpop = fpop, fpop = fpop->next_same_hash)    if (fpop->opcode == code && noperands == fpop->noperands	&& (op0 == 0 || rtx_equal_p (op0, fpop->ops[0]))	&& (op1 == 0 || rtx_equal_p (op1, fpop->ops[1]))	&& (op2 == 0 || rtx_equal_p (op2, fpop->ops[2])))      goto win;  /* We have never seen this operation before.  */  fpop = (struct fp_op *) xmalloc (sizeof (struct fp_op));  fpop->mem_offset = data_offset;  fpop->opcode = code;  fpop->noperands = noperands;  fpop->ops[0] = op0;  fpop->ops[1] = op1;  fpop->ops[2] = op2;  /* Compute the size using the rules in Appendix A of the RT Linkage     Convention (4.3/RT-PSD:5) manual.  These rules are a bit ambiguous,     but if we guess wrong, it will effect only efficiency, not correctness.  */  /* Size = 24 + 32 for each non-fp (or fr7) */  size = 24;  if (op0 && (GET_CODE (op0) != REG	      || ! FP_REGNO_P (REGNO (op0)) || REGNO (op0) == 23))    size += 32;  if (op1 && (GET_CODE (op1) != REG	      || ! FP_REGNO_P (REGNO (op1)) || REGNO (op1) == 23))    size += 32;

⌨️ 快捷键说明

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