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

📄 emit-rtl.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Emit RTL for the GNU C-Compiler expander.   Copyright (C) 1987, 1988, 1992 Free Software Foundation, Inc.This file is part of GNU CC.GNU CC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU CC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU CC; see the file COPYING.  If not, write tothe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  *//* Middle-to-low level generation of rtx code and insns.   This file contains the functions `gen_rtx', `gen_reg_rtx'   and `gen_label_rtx' that are the usual ways of creating rtl   expressions for most purposes.   It also has the functions for creating insns and linking   them in the doubly-linked chain.   The patterns of the insns are created by machine-dependent   routines in insn-emit.c, which is generated automatically from   the machine description.  These routines use `gen_rtx' to make   the individual rtx's of the pattern; what is machine dependent   is the kind of rtx's they make and what arguments they use.  */#include "config.h"#include "gvarargs.h"#include "rtl.h"#include "flags.h"#include "function.h"#include "expr.h"#include "regs.h"#include "insn-config.h"#include "real.h"#include <stdio.h>/* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function.   After rtl generation, it is 1 plus the largest register number used.  */int reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;/* This is *not* reset after each function.  It gives each CODE_LABEL   in the entire compilation a unique label number.  */static int label_num = 1;/* Lowest label number in current function.  */static int first_label_num;/* Highest label number in current function.   Zero means use the value of label_num instead.   This is nonzero only when belatedly compiling an inline function.  */static int last_label_num;/* Value label_num had when set_new_first_and_last_label_number was called.   If label_num has not changed since then, last_label_num is valid.  */static int base_label_num;/* Nonzero means do not generate NOTEs for source line numbers.  */static int no_line_numbers;/* Commonly used rtx's, so that we only need space for one copy.   These are initialized once for the entire compilation.   All of these except perhaps the floating-point CONST_DOUBLEs   are unique; no other rtx-object will be equal to any of these.  */rtx pc_rtx;			/* (PC) */rtx cc0_rtx;			/* (CC0) */rtx cc1_rtx;			/* (CC1) (not actually used nowadays) */rtx const0_rtx;			/* (CONST_INT 0) */rtx const1_rtx;			/* (CONST_INT 1) */rtx const2_rtx;			/* (CONST_INT 2) */rtx constm1_rtx;		/* (CONST_INT -1) */rtx const_true_rtx;		/* (CONST_INT STORE_FLAG_VALUE) *//* We record floating-point CONST_DOUBLEs in each floating-point mode for   the values of 0, 1, and 2.  For the integer entries and VOIDmode, we   record a copy of const[012]_rtx.  */rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];REAL_VALUE_TYPE dconst0;REAL_VALUE_TYPE dconst1;REAL_VALUE_TYPE dconst2;REAL_VALUE_TYPE dconstm1;/* All references to the following fixed hard registers go through   these unique rtl objects.  On machines where the frame-pointer and   arg-pointer are the same register, they use the same unique object.   After register allocation, other rtl objects which used to be pseudo-regs   may be clobbered to refer to the frame-pointer register.   But references that were originally to the frame-pointer can be   distinguished from the others because they contain frame_pointer_rtx.   In an inline procedure, the stack and frame pointer rtxs may not be   used for anything else.  */rtx stack_pointer_rtx;		/* (REG:Pmode STACK_POINTER_REGNUM) */rtx frame_pointer_rtx;		/* (REG:Pmode FRAME_POINTER_REGNUM) */rtx arg_pointer_rtx;		/* (REG:Pmode ARG_POINTER_REGNUM) */rtx struct_value_rtx;		/* (REG:Pmode STRUCT_VALUE_REGNUM) */rtx struct_value_incoming_rtx;	/* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */rtx static_chain_rtx;		/* (REG:Pmode STATIC_CHAIN_REGNUM) */rtx static_chain_incoming_rtx;	/* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */rtx pic_offset_table_rtx;	/* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */rtx virtual_incoming_args_rtx;	/* (REG:Pmode VIRTUAL_INCOMING_ARGS_REGNUM) */rtx virtual_stack_vars_rtx;	/* (REG:Pmode VIRTUAL_STACK_VARS_REGNUM) */rtx virtual_stack_dynamic_rtx;	/* (REG:Pmode VIRTUAL_STACK_DYNAMIC_REGNUM) */rtx virtual_outgoing_args_rtx;	/* (REG:Pmode VIRTUAL_OUTGOING_ARGS_REGNUM) *//* We make one copy of (const_int C) where C is in   [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]   to save space during the compilation and simplify comparisons of   integers.  */#define MAX_SAVED_CONST_INT 64static rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];/* The ends of the doubly-linked chain of rtl for the current function.   Both are reset to null at the start of rtl generation for the function.      start_sequence saves both of these on `sequence_stack' and then   starts a new, nested sequence of insns.  */static rtx first_insn = NULL;static rtx last_insn = NULL;/* INSN_UID for next insn emitted.   Reset to 1 for each function compiled.  */static int cur_insn_uid = 1;/* Line number and source file of the last line-number NOTE emitted.   This is used to avoid generating duplicates.  */static int last_linenum = 0;static char *last_filename = 0;/* A vector indexed by pseudo reg number.  The allocated length   of this vector is regno_pointer_flag_length.  Since this   vector is needed during the expansion phase when the total   number of registers in the function is not yet known,   it is copied and made bigger when necessary.  */char *regno_pointer_flag;int regno_pointer_flag_length;/* Indexed by pseudo register number, gives the rtx for that pseudo.   Allocated in parallel with regno_pointer_flag.  */rtx *regno_reg_rtx;/* Stack of pending (incomplete) sequences saved by `start_sequence'.   Each element describes one pending sequence.   The main insn-chain is saved in the last element of the chain,   unless the chain is empty.  */struct sequence_stack *sequence_stack;/* start_sequence and gen_sequence can make a lot of rtx expressions which are   shortly thrown away.  We use two mechanisms to prevent this waste:   First, we keep a list of the expressions used to represent the sequence   stack in sequence_element_free_list.   Second, for sizes up to 5 elements, we keep a SEQUENCE and its associated   rtvec for use by gen_sequence.  One entry for each size is sufficient   because most cases are calls to gen_sequence followed by immediately   emitting the SEQUENCE.  Reuse is safe since emitting a sequence is   destructive on the insn in it anyway and hence can't be redone.   We do not bother to save this cached data over nested function calls.   Instead, we just reinitialize them.  */#define SEQUENCE_RESULT_SIZE 5static struct sequence_stack *sequence_element_free_list;static rtx sequence_result[SEQUENCE_RESULT_SIZE];extern int rtx_equal_function_value_matters;/* Filename and line number of last line-number note,   whether we actually emitted it or not.  */extern char *emit_filename;extern int emit_lineno;rtx change_address ();void init_emit ();/* rtx gen_rtx (code, mode, [element1, ..., elementn])****	    This routine generates an RTX of the size specified by**	<code>, which is an RTX code.   The RTX structure is initialized**	from the arguments <element1> through <elementn>, which are**	interpreted according to the specific RTX type's format.   The**	special machine mode associated with the rtx (if any) is specified**	in <mode>.****	    gen_rtx() can be invoked in a way which resembles the lisp-like**	rtx it will generate.   For example, the following rtx structure:****	      (plus:QI (mem:QI (reg:SI 1))**		       (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))****		...would be generated by the following C code:****	    	gen_rtx (PLUS, QImode,**		    gen_rtx (MEM, QImode,**			gen_rtx (REG, SImode, 1)),**		    gen_rtx (MEM, QImode,**			gen_rtx (PLUS, SImode,**			    gen_rtx (REG, SImode, 2),**			    gen_rtx (REG, SImode, 3)))),*//*VARARGS2*/rtxgen_rtx (va_alist)     va_dcl{  va_list p;  enum rtx_code code;  enum machine_mode mode;  register int i;		/* Array indices...			*/  register char *fmt;		/* Current rtx's format...		*/  register rtx rt_val;		/* RTX to return to caller...		*/  va_start (p);  code = va_arg (p, enum rtx_code);  mode = va_arg (p, enum machine_mode);  if (code == CONST_INT)    {      HOST_WIDE_INT arg = va_arg (p, HOST_WIDE_INT);      if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)	return const_int_rtx[arg + MAX_SAVED_CONST_INT];      if (const_true_rtx && arg == STORE_FLAG_VALUE)	return const_true_rtx;      rt_val = rtx_alloc (code);      INTVAL (rt_val) = arg;    }  else if (code == REG)    {      int regno = va_arg (p, int);      /* In case the MD file explicitly references the frame pointer, have	 all such references point to the same frame pointer.  This is used	 during frame pointer elimination to distinguish the explicit	 references to these registers from pseudos that happened to be	 assigned to them.	 If we have eliminated the frame pointer or arg pointer, we will	 be using it as a normal register, for example as a spill register.	 In such cases, we might be accessing it in a mode that is not	 Pmode and therefore cannot use the pre-allocated rtx.	 Also don't do this when we are making new REGs in reload,	 since we don't want to get confused with the real pointers.  */      if (frame_pointer_rtx && regno == FRAME_POINTER_REGNUM && mode == Pmode	  && ! reload_in_progress)	return frame_pointer_rtx;#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM      if (arg_pointer_rtx && regno == ARG_POINTER_REGNUM && mode == Pmode	  && ! reload_in_progress)	return arg_pointer_rtx;#endif      if (stack_pointer_rtx && regno == STACK_POINTER_REGNUM && mode == Pmode	  && ! reload_in_progress)	return stack_pointer_rtx;      else	{	  rt_val = rtx_alloc (code);	  rt_val->mode = mode;	  REGNO (rt_val) = regno;	  return rt_val;	}    }  else    {      rt_val = rtx_alloc (code);	/* Allocate the storage space.  */      rt_val->mode = mode;		/* Store the machine mode...  */      fmt = GET_RTX_FORMAT (code);	/* Find the right format...  */      for (i = 0; i < GET_RTX_LENGTH (code); i++)	{	  switch (*fmt++)	    {	    case '0':		/* Unused field.  */	      break;	    case 'i':		/* An integer?  */	      XINT (rt_val, i) = va_arg (p, int);	      break;	    case 'w':		/* A wide integer? */	      XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);	      break;	    case 's':		/* A string?  */	      XSTR (rt_val, i) = va_arg (p, char *);	      break;	    case 'e':		/* An expression?  */	    case 'u':		/* An insn?  Same except when printing.  */	      XEXP (rt_val, i) = va_arg (p, rtx);	      break;	    case 'E':		/* An RTX vector?  */	      XVEC (rt_val, i) = va_arg (p, rtvec);	      break;	    default:	      abort();	    }	}    }  va_end (p);  return rt_val;		/* Return the new RTX...		*/}/* gen_rtvec (n, [rt1, ..., rtn])****	    This routine creates an rtvec and stores within it the**	pointers to rtx's which are its arguments.*//*VARARGS1*/rtvecgen_rtvec (va_alist)     va_dcl{  int n, i;  va_list p;  rtx *vector;  va_start (p);  n = va_arg (p, int);  if (n == 0)    return NULL_RTVEC;		/* Don't allocate an empty rtvec...	*/  vector = (rtx *) alloca (n * sizeof (rtx));  for (i = 0; i < n; i++)    vector[i] = va_arg (p, rtx);  va_end (p);  return gen_rtvec_v (n, vector);}rtvecgen_rtvec_v (n, argp)     int n;     rtx *argp;{  register int i;  register rtvec rt_val;  if (n == 0)    return NULL_RTVEC;		/* Don't allocate an empty rtvec...	*/  rt_val = rtvec_alloc (n);	/* Allocate an rtvec...			*/  for (i = 0; i < n; i++)    rt_val->elem[i].rtx = *argp++;  return rt_val;}/* Generate a REG rtx for a new pseudo register of mode MODE.   This pseudo is assigned the next sequential register number.  */rtxgen_reg_rtx (mode)     enum machine_mode mode;{  register rtx val;  /* Don't let anything called by or after reload create new registers     (actually, registers can't be created after flow, but this is a good     approximation).  */  if (reload_in_progress || reload_completed)    abort ();  /* Make sure regno_pointer_flag and regno_reg_rtx are large     enough to have an element for this pseudo reg number.  */  if (reg_rtx_no == regno_pointer_flag_length)    {      rtx *new1;      char *new =	(char *) oballoc (regno_pointer_flag_length * 2);      bzero (new, regno_pointer_flag_length * 2);      bcopy (regno_pointer_flag, new, regno_pointer_flag_length);      regno_pointer_flag = new;      new1 = (rtx *) oballoc (regno_pointer_flag_length * 2 * sizeof (rtx));      bzero (new1, regno_pointer_flag_length * 2 * sizeof (rtx));      bcopy (regno_reg_rtx, new1, regno_pointer_flag_length * sizeof (rtx));      regno_reg_rtx = new1;      regno_pointer_flag_length *= 2;    }  val = gen_rtx (REG, mode, reg_rtx_no);  regno_reg_rtx[reg_rtx_no++] = val;  return val;}/* Identify REG as a probable pointer register.  */voidmark_reg_pointer (reg)     rtx reg;{  REGNO_POINTER_FLAG (REGNO (reg)) = 1;}/* Return 1 plus largest pseudo reg number used in the current function.  */intmax_reg_num (){  return reg_rtx_no;}/* Return 1 + the largest label number used so far in the current function.  */intmax_label_num (){  if (last_label_num && label_num == base_label_num)    return last_label_num;  return label_num;}/* Return first label number used in this function (if any were used).  */intget_first_label_num (){  return first_label_num;}/* Return a value representing some low-order bits of X, where the number   of low-order bits is given by MODE.  Note that no conversion is done   between floating-point and fixed-point values, rather, the bit    representation is returned.   This function handles the cases in common between gen_lowpart, below,   and two variants in cse.c and combine.c.  These are the cases that can   be safely handled at all points in the compilation.   If this is not a case we can handle, return 0.  */rtxgen_lowpart_common (mode, x)     enum machine_mode mode;     register rtx x;{  int word = 0;  if (GET_MODE (x) == mode)    return x;  /* MODE must occupy no more words than the mode of X.  */  if (GET_MODE (x) != VOIDmode      && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD	  > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))	     / UNITS_PER_WORD)))

⌨️ 快捷键说明

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