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

📄 fr30.c

📁 linux下的gcc编译器
💻 C
📖 第 1 页 / 共 3 页
字号:
/* FR30 specific functions.   Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.   Contributed by Cygnus Solutions.   This file is part of GNU CC.   GNU CC is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the 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 of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with GNU CC; see the file COPYING.  If not, write to   the Free Software Foundation, 59 Temple Place - Suite 330,   Boston, MA 02111-1307, USA.  *//*{{{  Includes */ #include "config.h"#include "system.h"#include "rtl.h"#include "regs.h"#include "hard-reg-set.h"#include "real.h"#include "insn-config.h"#include "conditions.h"#include "insn-attr.h"#include "flags.h"#include "recog.h"#include "tree.h"#include "output.h"#include "expr.h"#include "obstack.h"#include "except.h"#include "function.h"#include "tm_p.h"#include "target.h"#include "target-def.h"/*}}}*//*{{{  Function Prologues & Epilogues */ /* Define the information needed to generate branch and scc insns.  This is   stored from the compare operation.  */struct rtx_def * fr30_compare_op0;struct rtx_def * fr30_compare_op1;/* The FR30 stack looks like this:             Before call                       After call   FP ->|                       |       |                       |        +-----------------------+       +-----------------------+       high         |                       |       |                       |       memory        |  local variables,     |       |  local variables,     |        |  reg save area, etc.  |       |  reg save area, etc.  |        |                       |       |                       |        +-----------------------+       +-----------------------+        |                       |       |                       |        | args to the func that |       |  args to this func.   |        | is being called that  |       |                       |   SP ->| do not fit in regs    |       |                       |        +-----------------------+       +-----------------------+                                        |  args that used to be |  \                                        | in regs; only created |   |  pretend_size                                    AP-> |   for vararg funcs    |  /                                          +-----------------------+                                            |                       |  \                                          |  register save area   |   |                                        |                       |   |					+-----------------------+   |  reg_size                                        |    return address     |   | 					+-----------------------+   |                                   FP ->|   previous frame ptr  |  /                                        +-----------------------+                                            |                       |  \                                           |  local variables      |   |  var_size                                         |                       |  /                                          +-----------------------+                                            |                       |  \            low                                |  room for args to     |   |     memory                             |  other funcs called   |   |  args_size                                             |  from this one        |   |                                   SP ->|                       |  /                                          +-----------------------+          Note, AP is a fake hard register.  It will be eliminated in favor of   SP or FP as appropriate.   Note, Some or all of the stack sections above may be omitted if they    are not needed.  *//* Structure to be filled in by fr30_compute_frame_size() with register   save masks, and offsets for the current function.  */struct fr30_frame_info{  unsigned int total_size;	/* # Bytes that the entire frame takes up. */  unsigned int pretend_size;	/* # Bytes we push and pretend caller did. */  unsigned int args_size;	/* # Bytes that outgoing arguments take up. */  unsigned int reg_size;	/* # Bytes needed to store regs. */  unsigned int var_size;	/* # Bytes that variables take up. */  unsigned int frame_size;      /* # Bytes in current frame.  */  unsigned int gmask;		/* Mask of saved registers. */  unsigned int save_fp;		/* Nonzero if frame pointer must be saved. */  unsigned int save_rp;		/* Nonzero if return popinter must be saved. */  int          initialised;	/* Nonzero if frame size already calculated. */};/* Current frame information calculated by fr30_compute_frame_size().  */static struct fr30_frame_info 	current_frame_info;/* Zero structure to initialize current_frame_info.  */static struct fr30_frame_info 	zero_frame_info;static rtx fr30_pass_by_reference PARAMS ((tree, tree));static rtx fr30_pass_by_value PARAMS ((tree, tree));#define FRAME_POINTER_MASK 	(1 << (FRAME_POINTER_REGNUM))#define RETURN_POINTER_MASK 	(1 << (RETURN_POINTER_REGNUM))/* Tell prologue and epilogue if register REGNO should be saved / restored.   The return address and frame pointer are treated separately.   Don't consider them here.  */#define MUST_SAVE_REGISTER(regno)      \  (   (regno) != RETURN_POINTER_REGNUM \   && (regno) != FRAME_POINTER_REGNUM  \   &&   regs_ever_live [regno]         \   && ! call_used_regs [regno]         )#define MUST_SAVE_FRAME_POINTER	 (regs_ever_live [FRAME_POINTER_REGNUM]  || frame_pointer_needed)#define MUST_SAVE_RETURN_POINTER (regs_ever_live [RETURN_POINTER_REGNUM] || current_function_profile)#if UNITS_PER_WORD == 4#define WORD_ALIGN(SIZE) (((SIZE) + 3) & ~3)#endif/* Initialize the GCC target structure.  */#undef TARGET_ASM_ALIGNED_HI_OP#define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"#undef TARGET_ASM_ALIGNED_SI_OP#define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"struct gcc_target targetm = TARGET_INITIALIZER;/* Returns the number of bytes offset between FROM_REG and TO_REG   for the current function.  As a side effect it fills in the    current_frame_info structure, if the data is available.  */unsigned intfr30_compute_frame_size (from_reg, to_reg)     int from_reg;     int to_reg;{  int 		regno;  unsigned int 	return_value;  unsigned int	var_size;  unsigned int	args_size;  unsigned int	pretend_size;  unsigned int 	reg_size;  unsigned int 	gmask;  var_size	= WORD_ALIGN (get_frame_size ());  args_size	= WORD_ALIGN (current_function_outgoing_args_size);  pretend_size	= current_function_pretend_args_size;  reg_size	= 0;  gmask		= 0;  /* Calculate space needed for registers.  */  for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno ++)    {      if (MUST_SAVE_REGISTER (regno))	{	  reg_size += UNITS_PER_WORD;	  gmask |= 1 << regno;	}    }  current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;  current_frame_info.save_rp = MUST_SAVE_RETURN_POINTER;  reg_size += (current_frame_info.save_fp + current_frame_info.save_rp)	       * UNITS_PER_WORD;  /* Save computed information.  */  current_frame_info.pretend_size = pretend_size;  current_frame_info.var_size     = var_size;  current_frame_info.args_size    = args_size;  current_frame_info.reg_size	  = reg_size;  current_frame_info.frame_size   = args_size + var_size;  current_frame_info.total_size   = args_size + var_size + reg_size + pretend_size;  current_frame_info.gmask	  = gmask;  current_frame_info.initialised  = reload_completed;  /* Calculate the required distance.  */  return_value = 0;    if (to_reg == STACK_POINTER_REGNUM)    return_value += args_size + var_size;    if (from_reg == ARG_POINTER_REGNUM)    return_value += reg_size;  return return_value;}/* Called after register allocation to add any instructions needed for the   prologue.  Using a prologue insn is favored compared to putting all of the   instructions in output_function_prologue(), since it allows the scheduler   to intermix instructions with the saves of the caller saved registers.  In   some cases, it might be necessary to emit a barrier instruction as the last   insn to prevent such scheduling.  */voidfr30_expand_prologue (){  int regno;  rtx insn;  if (! current_frame_info.initialised)    fr30_compute_frame_size (0, 0);  /* This cases shouldn't happen.  Catch it now.  */  if (current_frame_info.total_size == 0      && current_frame_info.gmask)    abort ();  /* Allocate space for register arguments if this is a variadic function.  */  if (current_frame_info.pretend_size)    {      int regs_to_save = current_frame_info.pretend_size / UNITS_PER_WORD;            /* Push argument registers into the pretend arg area.  */      for (regno = FIRST_ARG_REGNUM + FR30_NUM_ARG_REGS; regno --, regs_to_save --;)        {	  insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));	  RTX_FRAME_RELATED_P (insn) = 1;	}    }  if (current_frame_info.gmask)    {      /* Save any needed call-saved regs.  */      for (regno = STACK_POINTER_REGNUM; regno--;)	{	  if ((current_frame_info.gmask & (1 << regno)) != 0)	    {	      insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));	      RTX_FRAME_RELATED_P (insn) = 1;	    }	}    }  /* Save return address if necessary.  */  if (current_frame_info.save_rp)    {      insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode,       						     RETURN_POINTER_REGNUM)));      RTX_FRAME_RELATED_P (insn) = 1;    }  /* Save old frame pointer and create new one, if necessary.  */  if (current_frame_info.save_fp)    {      if (current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))        {	  int enter_size = current_frame_info.frame_size + UNITS_PER_WORD;	  rtx pattern;	  	  insn = emit_insn (gen_enter_func (GEN_INT (enter_size)));          RTX_FRAME_RELATED_P (insn) = 1;	  	  pattern = PATTERN (insn);	  	  /* Also mark all 3 subexpressions as RTX_FRAME_RELATED_P. */          if (GET_CODE (pattern) == PARALLEL)            {              int x;              for (x = XVECLEN (pattern, 0); x--;)		{		  rtx part = XVECEXP (pattern, 0, x);		  		  /* One of the insns in the ENTER pattern updates the		     frame pointer.  If we do not actually need the frame		     pointer in this function then this is a side effect		     rather than a desired effect, so we do not mark that		     insn as being related to the frame set up.  Doing this		     allows us to compile the crash66.C test file in the		     G++ testsuite.  */		  if (! frame_pointer_needed		      && GET_CODE (part) == SET		      && REGNO (SET_DEST (part)) == HARD_FRAME_POINTER_REGNUM)		    RTX_FRAME_RELATED_P (part) = 0;		  else		    RTX_FRAME_RELATED_P (part) = 1;		}            }	}      else	{	  insn = emit_insn (gen_movsi_push (frame_pointer_rtx));          RTX_FRAME_RELATED_P (insn) = 1;	  if (frame_pointer_needed)	    {	      insn = emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));	      RTX_FRAME_RELATED_P (insn) = 1;	    }	}    }  /* Allocate the stack frame.  */  if (current_frame_info.frame_size == 0)    ; /* Nothing to do.  */  else if (current_frame_info.save_fp	   && current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))    ; /* Nothing to do.  */  else if (current_frame_info.frame_size <= 512)    {      insn = emit_insn (gen_add_to_stack (GEN_INT (- current_frame_info.frame_size)));      RTX_FRAME_RELATED_P (insn) = 1;    }  else    {      rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);      insn = emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));      RTX_FRAME_RELATED_P (insn) = 1;      insn = emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));      RTX_FRAME_RELATED_P (insn) = 1;    }  if (current_function_profile)    emit_insn (gen_blockage ());}/* Called after register allocation to add any instructions needed for the   epilogue.  Using an epilogue insn is favored compared to putting all of the   instructions in output_function_epilogue(), since it allows the scheduler   to intermix instructions with the restores of the caller saved registers.   In some cases, it might be necessary to emit a barrier instruction as the   first insn to prevent such scheduling.  */voidfr30_expand_epilogue (){  int regno;  /* Perform the inversion operations of the prologue.  */  if (! current_frame_info.initialised)    abort ();  /* Pop local variables and arguments off the stack.     If frame_pointer_needed is TRUE then the frame pointer register     has actually been used as a frame pointer, and we can recover     the stack pointer from it, otherwise we must unwind the stack     manually.  */  if (current_frame_info.frame_size > 0)    {      if (current_frame_info.save_fp && frame_pointer_needed)	{	  emit_insn (gen_leave_func ());	  current_frame_info.save_fp = 0;	}      else if (current_frame_info.frame_size <= 508)	emit_insn (gen_add_to_stack		   (GEN_INT (current_frame_info.frame_size)));      else	{	  rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);	  emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));

⌨️ 快捷键说明

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