📄 crx.c
字号:
/* Output routines for GCC for CRX. Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of GCC. GCC 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. GCC 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 GCC; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *//*****************************************************************************//* HEADER INCLUDES *//*****************************************************************************/#include "config.h"#include "system.h"#include "coretypes.h"#include "tm.h"#include "rtl.h"#include "tree.h"#include "tm_p.h"#include "regs.h"#include "hard-reg-set.h"#include "real.h"#include "insn-config.h"#include "conditions.h"#include "output.h"#include "insn-codes.h"#include "insn-attr.h"#include "flags.h"#include "except.h"#include "function.h"#include "recog.h"#include "expr.h"#include "optabs.h"#include "toplev.h"#include "basic-block.h"#include "target.h"#include "target-def.h"/*****************************************************************************//* DEFINITIONS *//*****************************************************************************//* Maximum number of register used for passing parameters. */#define MAX_REG_FOR_PASSING_ARGS 6/* Minimum number register used for passing parameters. */#define MIN_REG_FOR_PASSING_ARGS 2/* The maximum count of words supported in the assembly of the architecture in * a push/pop instruction. */#define MAX_COUNT 8/* Predicate is true if the current function is a 'noreturn' function, i.e. it * is qualified as volatile. */#define FUNC_IS_NORETURN_P(decl) (TREE_THIS_VOLATILE (decl))/* The following macros are used in crx_decompose_address () *//* Returns the factor of a scaled index address or -1 if invalid. */#define SCALE_FOR_INDEX_P(X) \ (GET_CODE (X) == CONST_INT ? \ (INTVAL (X) == 1 ? 1 : \ INTVAL (X) == 2 ? 2 : \ INTVAL (X) == 4 ? 4 : \ INTVAL (X) == 8 ? 8 : \ -1) : \ -1)/* Nonzero if the rtx X is a signed const int of n bits */#define RTX_SIGNED_INT_FITS_N_BITS(X,n) \ ((GET_CODE (X) == CONST_INT \ && SIGNED_INT_FITS_N_BITS (INTVAL (X), n)) ? 1 : 0)/* Nonzero if the rtx X is an unsigned const int of n bits. */#define RTX_UNSIGNED_INT_FITS_N_BITS(X, n) \ ((GET_CODE (X) == CONST_INT \ && UNSIGNED_INT_FITS_N_BITS (INTVAL (X), n)) ? 1 : 0)/*****************************************************************************//* STATIC VARIABLES *//*****************************************************************************//* Nonzero if the last param processed is passed in a register. */static int last_parm_in_reg;/* Will hold the number of the last register the prologue saves, -1 if no * register is saved. */static int last_reg_to_save;/* Each object in the array is a register number. Mark 1 for registers that * need to be saved. */static int save_regs[FIRST_PSEUDO_REGISTER];/* Number of bytes saved on the stack for non-scratch registers */static int sum_regs = 0;/* Number of bytes saved on the stack for local variables. */static int local_vars_size;/* The sum of 2 sizes: locals vars and padding byte for saving the registers. * Used in expand_prologue () and expand_epilogue (). */static int size_for_adjusting_sp;/* In case of a POST_INC or POST_DEC memory reference, we must report the mode * of the memory reference from PRINT_OPERAND to PRINT_OPERAND_ADDRESS. */static enum machine_mode output_memory_reference_mode;/*****************************************************************************//* GLOBAL VARIABLES *//*****************************************************************************//* Table of machine attributes. */const struct attribute_spec crx_attribute_table[];/* Test and compare insns use these globals to generate branch insns. */rtx crx_compare_op0 = NULL_RTX;rtx crx_compare_op1 = NULL_RTX;/*****************************************************************************//* TARGETM FUNCTION PROTOTYPES *//*****************************************************************************/static bool crx_fixed_condition_code_regs (unsigned int *, unsigned int *);static rtx crx_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED, int incoming ATTRIBUTE_UNUSED);static bool crx_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED);static int crx_address_cost (rtx);/*****************************************************************************//* STACK LAYOUT AND CALLING CONVENTIONS *//*****************************************************************************/#undef TARGET_FIXED_CONDITION_CODE_REGS#define TARGET_FIXED_CONDITION_CODE_REGS crx_fixed_condition_code_regs#undef TARGET_STRUCT_VALUE_RTX#define TARGET_STRUCT_VALUE_RTX crx_struct_value_rtx#undef TARGET_RETURN_IN_MEMORY#define TARGET_RETURN_IN_MEMORY crx_return_in_memory/*****************************************************************************//* RELATIVE COSTS OF OPERATIONS *//*****************************************************************************/#undef TARGET_ADDRESS_COST#define TARGET_ADDRESS_COST crx_address_cost/*****************************************************************************//* TARGET-SPECIFIC USES OF `__attribute__' *//*****************************************************************************/#undef TARGET_ATTRIBUTE_TABLE#define TARGET_ATTRIBUTE_TABLE crx_attribute_tableconst struct attribute_spec crx_attribute_table[] = { /* ISRs have special prologue and epilogue requirements. */ {"interrupt", 0, 0, false, true, true, NULL}, {NULL, 0, 0, false, false, false, NULL}};/* Initialize 'targetm' variable which contains pointers to functions and data * relating to the target machine. */struct gcc_target targetm = TARGET_INITIALIZER;/*****************************************************************************//* TARGET HOOK IMPLEMENTATIONS *//*****************************************************************************//* Return the fixed registers used for condition codes. */static boolcrx_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2){ *p1 = CC_REGNUM; *p2 = INVALID_REGNUM; return true;}/* Implements hook TARGET_STRUCT_VALUE_RTX. */static rtxcrx_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED, int incoming ATTRIBUTE_UNUSED){ return gen_rtx_REG (Pmode, CRX_STRUCT_VALUE_REGNUM);}/* Implements hook TARGET_RETURN_IN_MEMORY. */static boolcrx_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED){ if (TYPE_MODE (type) == BLKmode) { HOST_WIDE_INT size = int_size_in_bytes (type); return (size == -1 || size > 8); } else return false;}/*****************************************************************************//* MACRO IMPLEMENTATIONS *//*****************************************************************************//* STACK LAYOUT AND CALLING CONVENTIONS ROUTINES *//* --------------------------------------------- *//* Return nonzero if the current function being compiled is an interrupt * function as specified by the "interrupt" attribute. */intcrx_interrupt_function_p (void){ tree attributes; attributes = TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl)); return lookup_attribute ("interrupt", attributes) != NULL_TREE;}/* Compute values for the array save_regs and the variable sum_regs. The index * of save_regs is numbers of register, each will get 1 if we need to save it * in the current function, 0 if not. sum_regs is the total sum of the * registers being saved. */static voidcrx_compute_save_regs (void){ unsigned int regno; /* initialize here so in case the function is no-return it will be -1. */ last_reg_to_save = -1; /* No need to save any registers if the function never returns. */ if (FUNC_IS_NORETURN_P (current_function_decl)) return; /* Initialize the number of bytes to be saved. */ sum_regs = 0; for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) { if (fixed_regs[regno]) { save_regs[regno] = 0; continue; } /* If this reg is used and not call-used (except RA), save it. */ if (crx_interrupt_function_p ()) { if (!current_function_is_leaf && call_used_regs[regno]) /* this is a volatile reg in a non-leaf interrupt routine - save it * for the sake of its sons. */ save_regs[regno] = 1; else if (regs_ever_live[regno]) /* This reg is used - save it. */ save_regs[regno] = 1; else /* This reg is not used, and is not a volatile - don't save. */ save_regs[regno] = 0; } else { /* If this reg is used and not call-used (except RA), save it. */ if (regs_ever_live[regno] && (!call_used_regs[regno] || regno == RETURN_ADDRESS_REGNUM)) save_regs[regno] = 1; else save_regs[regno] = 0; } } for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) if (save_regs[regno] == 1) { last_reg_to_save = regno; sum_regs += UNITS_PER_WORD; }}/* Compute the size of the local area and the size to be adjusted by the * prologue and epilogue. */static voidcrx_compute_frame (void){ /* For aligning the local variables. */ int stack_alignment = STACK_BOUNDARY / BITS_PER_UNIT; int padding_locals; /* Padding needed for each element of the frame. */ local_vars_size = get_frame_size (); /* Align to the stack alignment. */ padding_locals = local_vars_size % stack_alignment; if (padding_locals) padding_locals = stack_alignment - padding_locals; local_vars_size += padding_locals; size_for_adjusting_sp = local_vars_size + (ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0);}/* Implements the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET. */intcrx_initial_elimination_offset (int from, int to){ /* Compute this since we need to use sum_regs. */ crx_compute_save_regs (); /* Compute this since we need to use local_vars_size. */ crx_compute_frame (); if ((from) == FRAME_POINTER_REGNUM && (to) == STACK_POINTER_REGNUM) return (ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0); else if ((from) == ARG_POINTER_REGNUM && (to) == FRAME_POINTER_REGNUM) return (sum_regs + local_vars_size); else if ((from) == ARG_POINTER_REGNUM && (to) == STACK_POINTER_REGNUM) return (sum_regs + local_vars_size + (ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0)); else abort ();}/* REGISTER USAGE *//* -------------- *//* Return the class number of the smallest class containing reg number REGNO. * This could be a conditional expression or could index an array. */enum reg_classcrx_regno_reg_class (int regno){ if (regno >= 0 && regno < SP_REGNUM) return NOSP_REGS; if (regno == SP_REGNUM) return GENERAL_REGS; if (regno == LO_REGNUM) return LO_REGS; if (regno == HI_REGNUM) return HI_REGS; return NO_REGS;}/* Transfer between HILO_REGS and memory via secondary reloading. */enum reg_classcrx_secondary_reload_class (enum reg_class class, enum machine_mode mode ATTRIBUTE_UNUSED, rtx x ATTRIBUTE_UNUSED){ if (reg_classes_intersect_p (class, HILO_REGS) && true_regnum (x) == -1) return GENERAL_REGS; return NO_REGS;}/* Return 1 if hard register REGNO can hold a value of machine-mode MODE. */intcrx_hard_regno_mode_ok (int regno, enum machine_mode mode){ /* CC can only hold CCmode values. */ if (regno == CC_REGNUM) return GET_MODE_CLASS (mode) == MODE_CC; if (GET_MODE_CLASS (mode) == MODE_CC) return 0; /* HILO registers can only hold SImode and DImode */ if (HILO_REGNO_P (regno)) return mode == SImode || mode == DImode; return 1;}/* PASSING FUNCTION ARGUMENTS *//* -------------------------- *//* If enough param regs are available for passing the param of type TYPE return * the number of registers needed else 0. */static intenough_regs_for_param (CUMULATIVE_ARGS * cum, tree type, enum machine_mode mode){ int type_size; int remaining_size; if (mode != BLKmode) type_size = GET_MODE_BITSIZE (mode); else type_size = int_size_in_bytes (type) * BITS_PER_UNIT; remaining_size = BITS_PER_WORD * (MAX_REG_FOR_PASSING_ARGS - (MIN_REG_FOR_PASSING_ARGS + cum->ints) + 1); /* Any variable which is too big to pass in two registers, will pass on * stack. */ if ((remaining_size >= type_size) && (type_size <= 2 * BITS_PER_WORD)) return (type_size + BITS_PER_WORD - 1) / BITS_PER_WORD; return 0;}/* Implements the macro FUNCTION_ARG defined in crx.h. */rtxcrx_function_arg (CUMULATIVE_ARGS * cum, enum machine_mode mode, tree type, int named ATTRIBUTE_UNUSED){ last_parm_in_reg = 0; /* Function_arg () is called with this type just after all the args have had * their registers assigned. The rtx that function_arg returns from this type * is supposed to pass to 'gen_call' but currently it is not implemented (see * macro GEN_CALL). */ if (type == void_type_node) return NULL_RTX; if (targetm.calls.must_pass_in_stack (mode, type) || (cum->ints < 0)) return NULL_RTX; if (mode == BLKmode) { /* Enable structures that need padding bytes at the end to pass to a * function in registers. */ if (enough_regs_for_param (cum, type, mode) != 0) { last_parm_in_reg = 1; return gen_rtx_REG (mode, MIN_REG_FOR_PASSING_ARGS + cum->ints); } } if (MIN_REG_FOR_PASSING_ARGS + cum->ints > MAX_REG_FOR_PASSING_ARGS) return NULL_RTX; else { if (enough_regs_for_param (cum, type, mode) != 0) { last_parm_in_reg = 1; return gen_rtx_REG (mode, MIN_REG_FOR_PASSING_ARGS + cum->ints); } } return NULL_RTX;}/* Implements the macro INIT_CUMULATIVE_ARGS defined in crx.h. */voidcrx_init_cumulative_args (CUMULATIVE_ARGS * cum, tree fntype, rtx libfunc ATTRIBUTE_UNUSED){ tree param, next_param; cum->ints = 0; /* Determine if this function has variable arguments. This is indicated by * the last argument being 'void_type_mode' if there are no variable * arguments. Change here for a different vararg. */ for (param = (fntype) ? TYPE_ARG_TYPES (fntype) : 0; param != (tree) 0; param = next_param) { next_param = TREE_CHAIN (param);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -