?? mips.c.svn-base
字號(hào):
/* Subroutines used for MIPS code generation. Copyright (C) 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Contributed by A. Lichnewsky, lich@inria.inria.fr. Changes by Michael Meissner, meissner@osf.org. 64 bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and Brendan Eich, brendan@microunity.com.This file is part of GCC.GCC 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.GCC 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 GCC; see the file COPYING. If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA. */#include "config.h"#include "system.h"#include "coretypes.h"#include "tm.h"#include <signal.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 "recog.h"#include "toplev.h"#include "output.h"#include "tree.h"#include "function.h"#include "expr.h"#include "optabs.h"#include "flags.h"#include "reload.h"#include "tm_p.h"#include "ggc.h"#include "gstab.h"#include "hashtab.h"#include "debug.h"#include "target.h"#include "target-def.h"#include "integrate.h"#include "langhooks.h"#include "cfglayout.h"#include "sched-int.h"#include "tree-gimple.h"/* True if X is an unspec wrapper around a SYMBOL_REF or LABEL_REF. */#define UNSPEC_ADDRESS_P(X) \ (GET_CODE (X) == UNSPEC \ && XINT (X, 1) >= UNSPEC_ADDRESS_FIRST \ && XINT (X, 1) < UNSPEC_ADDRESS_FIRST + NUM_SYMBOL_TYPES)/* Extract the symbol or label from UNSPEC wrapper X. */#define UNSPEC_ADDRESS(X) \ XVECEXP (X, 0, 0)/* Extract the symbol type from UNSPEC wrapper X. */#define UNSPEC_ADDRESS_TYPE(X) \ ((enum mips_symbol_type) (XINT (X, 1) - UNSPEC_ADDRESS_FIRST))/* The maximum distance between the top of the stack frame and the value $sp has when we save & restore registers. Use a maximum gap of 0x100 in the mips16 case. We can then use unextended instructions to save and restore registers, and to allocate and deallocate the top part of the frame. The value in the !mips16 case must be a SMALL_OPERAND and must preserve the maximum stack alignment. */#define MIPS_MAX_FIRST_STACK_STEP (TARGET_MIPS16 ? 0x100 : 0x7ff0)/* True if INSN is a mips.md pattern or asm statement. */#define USEFUL_INSN_P(INSN) \ (INSN_P (INSN) \ && GET_CODE (PATTERN (INSN)) != USE \ && GET_CODE (PATTERN (INSN)) != CLOBBER \ && GET_CODE (PATTERN (INSN)) != ADDR_VEC \ && GET_CODE (PATTERN (INSN)) != ADDR_DIFF_VEC)/* If INSN is a delayed branch sequence, return the first instruction in the sequence, otherwise return INSN itself. */#define SEQ_BEGIN(INSN) \ (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \ ? XVECEXP (PATTERN (INSN), 0, 0) \ : (INSN))/* Likewise for the last instruction in a delayed branch sequence. */#define SEQ_END(INSN) \ (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \ ? XVECEXP (PATTERN (INSN), 0, XVECLEN (PATTERN (INSN), 0) - 1) \ : (INSN))/* Execute the following loop body with SUBINSN set to each instruction between SEQ_BEGIN (INSN) and SEQ_END (INSN) inclusive. */#define FOR_EACH_SUBINSN(SUBINSN, INSN) \ for ((SUBINSN) = SEQ_BEGIN (INSN); \ (SUBINSN) != NEXT_INSN (SEQ_END (INSN)); \ (SUBINSN) = NEXT_INSN (SUBINSN))/* Classifies an address. ADDRESS_REG A natural register + offset address. The register satisfies mips_valid_base_register_p and the offset is a const_arith_operand. ADDRESS_LO_SUM A LO_SUM rtx. The first operand is a valid base register and the second operand is a symbolic address. ADDRESS_CONST_INT A signed 16-bit constant address. ADDRESS_SYMBOLIC: A constant symbolic address (equivalent to CONSTANT_SYMBOLIC). */enum mips_address_type { ADDRESS_REG, ADDRESS_LO_SUM, ADDRESS_CONST_INT, ADDRESS_SYMBOLIC};/* Classifies the prototype of a builtin function. */enum mips_function_type{ MIPS_V2SF_FTYPE_V2SF, MIPS_V2SF_FTYPE_V2SF_V2SF, MIPS_V2SF_FTYPE_V2SF_V2SF_INT, MIPS_V2SF_FTYPE_V2SF_V2SF_V2SF_V2SF, MIPS_V2SF_FTYPE_SF_SF, MIPS_INT_FTYPE_V2SF_V2SF, MIPS_INT_FTYPE_V2SF_V2SF_V2SF_V2SF, MIPS_INT_FTYPE_SF_SF, MIPS_INT_FTYPE_DF_DF, MIPS_SF_FTYPE_V2SF, MIPS_SF_FTYPE_SF, MIPS_SF_FTYPE_SF_SF, MIPS_DF_FTYPE_DF, MIPS_DF_FTYPE_DF_DF, /* The last type. */ MIPS_MAX_FTYPE_MAX};/* Specifies how a builtin function should be converted into rtl. */enum mips_builtin_type{ /* The builtin corresponds directly to an .md pattern. The return value is mapped to operand 0 and the arguments are mapped to operands 1 and above. */ MIPS_BUILTIN_DIRECT, /* The builtin corresponds to a comparison instruction followed by a mips_cond_move_tf_ps pattern. The first two arguments are the values to compare and the second two arguments are the vector operands for the movt.ps or movf.ps instruction (in assembly order). */ MIPS_BUILTIN_MOVF, MIPS_BUILTIN_MOVT, /* The builtin corresponds to a V2SF comparison instruction. Operand 0 of this instruction is the result of the comparison, which has mode CCV2 or CCV4. The function arguments are mapped to operands 1 and above. The function's return value is an SImode boolean that is true under the following conditions: MIPS_BUILTIN_CMP_ANY: one of the registers is true MIPS_BUILTIN_CMP_ALL: all of the registers are true MIPS_BUILTIN_CMP_LOWER: the first register is true MIPS_BUILTIN_CMP_UPPER: the second register is true. */ MIPS_BUILTIN_CMP_ANY, MIPS_BUILTIN_CMP_ALL, MIPS_BUILTIN_CMP_UPPER, MIPS_BUILTIN_CMP_LOWER, /* As above, but the instruction only sets a single $fcc register. */ MIPS_BUILTIN_CMP_SINGLE};/* Invokes MACRO (COND) for each c.cond.fmt condition. */#define MIPS_FP_CONDITIONS(MACRO) \ MACRO (f), \ MACRO (un), \ MACRO (eq), \ MACRO (ueq), \ MACRO (olt), \ MACRO (ult), \ MACRO (ole), \ MACRO (ule), \ MACRO (sf), \ MACRO (ngle), \ MACRO (seq), \ MACRO (ngl), \ MACRO (lt), \ MACRO (nge), \ MACRO (le), \ MACRO (ngt)/* Enumerates the codes above as MIPS_FP_COND_<X>. */#define DECLARE_MIPS_COND(X) MIPS_FP_COND_ ## Xenum mips_fp_condition { MIPS_FP_CONDITIONS (DECLARE_MIPS_COND)};/* Index X provides the string representation of MIPS_FP_COND_<X>. */#define STRINGIFY(X) #Xstatic const char *const mips_fp_conditions[] = { MIPS_FP_CONDITIONS (STRINGIFY)};/* A function to save or store a register. The first argument is the register and the second is the stack slot. */typedef void (*mips_save_restore_fn) (rtx, rtx);struct mips16_constant;struct mips_arg_info;struct mips_address_info;struct mips_integer_op;struct mips_sim;static enum mips_symbol_type mips_classify_symbol (rtx);static void mips_split_const (rtx, rtx *, HOST_WIDE_INT *);static bool mips_offset_within_object_p (rtx, HOST_WIDE_INT);static bool mips_valid_base_register_p (rtx, enum machine_mode, int);static bool mips_symbolic_address_p (enum mips_symbol_type, enum machine_mode);static bool mips_classify_address (struct mips_address_info *, rtx, enum machine_mode, int);static int mips_symbol_insns (enum mips_symbol_type);static bool mips16_unextended_reference_p (enum machine_mode mode, rtx, rtx);static rtx mips_force_temporary (rtx, rtx);static rtx mips_split_symbol (rtx, rtx);static rtx mips_unspec_offset_high (rtx, rtx, rtx, enum mips_symbol_type);static rtx mips_add_offset (rtx, rtx, HOST_WIDE_INT);static unsigned int mips_build_shift (struct mips_integer_op *, HOST_WIDE_INT);static unsigned int mips_build_lower (struct mips_integer_op *, unsigned HOST_WIDE_INT);static unsigned int mips_build_integer (struct mips_integer_op *, unsigned HOST_WIDE_INT);static void mips_move_integer (rtx, unsigned HOST_WIDE_INT);static void mips_legitimize_const_move (enum machine_mode, rtx, rtx);static int m16_check_op (rtx, int, int, int);static bool mips_rtx_costs (rtx, int, int, int *);static int mips_address_cost (rtx);static void mips_emit_compare (enum rtx_code *, rtx *, rtx *, bool);static void mips_load_call_address (rtx, rtx, int);static bool mips_function_ok_for_sibcall (tree, tree);static void mips_block_move_straight (rtx, rtx, HOST_WIDE_INT);static void mips_adjust_block_mem (rtx, HOST_WIDE_INT, rtx *, rtx *);static void mips_block_move_loop (rtx, rtx, HOST_WIDE_INT);static void mips_arg_info (const CUMULATIVE_ARGS *, enum machine_mode, tree, int, struct mips_arg_info *);static bool mips_get_unaligned_mem (rtx *, unsigned int, int, rtx *, rtx *);static void mips_set_architecture (const struct mips_cpu_info *);static void mips_set_tune (const struct mips_cpu_info *);static struct machine_function *mips_init_machine_status (void);static void print_operand_reloc (FILE *, rtx, const char **);#if TARGET_IRIXstatic void irix_output_external_libcall (rtx);#endifstatic void mips_file_start (void);static void mips_file_end (void);static bool mips_rewrite_small_data_p (rtx);static int mips_small_data_pattern_1 (rtx *, void *);static int mips_rewrite_small_data_1 (rtx *, void *);static bool mips_function_has_gp_insn (void);static unsigned int mips_global_pointer (void);static bool mips_save_reg_p (unsigned int);static void mips_save_restore_reg (enum machine_mode, int, HOST_WIDE_INT, mips_save_restore_fn);static void mips_for_each_saved_reg (HOST_WIDE_INT, mips_save_restore_fn);static void mips_output_cplocal (void);static void mips_emit_loadgp (void);static void mips_output_function_prologue (FILE *, HOST_WIDE_INT);static void mips_set_frame_expr (rtx);static rtx mips_frame_set (rtx, rtx);static void mips_save_reg (rtx, rtx);static void mips_output_function_epilogue (FILE *, HOST_WIDE_INT);static void mips_restore_reg (rtx, rtx);static void mips_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);static int symbolic_expression_p (rtx);static void mips_select_rtx_section (enum machine_mode, rtx, unsigned HOST_WIDE_INT);static void mips_function_rodata_section (tree);static bool mips_in_small_data_p (tree);static int mips_fpr_return_fields (tree, tree *);static bool mips_return_in_msb (tree);static rtx mips_return_fpr_pair (enum machine_mode mode, enum machine_mode mode1, HOST_WIDE_INT, enum machine_mode mode2, HOST_WIDE_INT);static rtx mips16_gp_pseudo_reg (void);static void mips16_fp_args (FILE *, int, int);static void build_mips16_function_stub (FILE *);static rtx dump_constants_1 (enum machine_mode, rtx, rtx);static void dump_constants (struct mips16_constant *, rtx);static int mips16_insn_length (rtx);static int mips16_rewrite_pool_refs (rtx *, void *);static void mips16_lay_out_constants (void);static void mips_sim_reset (struct mips_sim *);static void mips_sim_init (struct mips_sim *, state_t);static void mips_sim_next_cycle (struct mips_sim *);static void mips_sim_wait_reg (struct mips_sim *, rtx, rtx);static int mips_sim_wait_regs_2 (rtx *, void *);static void mips_sim_wait_regs_1 (rtx *, void *);static void mips_sim_wait_regs (struct mips_sim *, rtx);static void mips_sim_wait_units (struct mips_sim *, rtx);static void mips_sim_wait_insn (struct mips_sim *, rtx);static void mips_sim_record_set (rtx, rtx, void *);static void mips_sim_issue_insn (struct mips_sim *, rtx);static void mips_sim_issue_nop (struct mips_sim *);static void mips_sim_finish_insn (struct mips_sim *, rtx);static void vr4130_avoid_branch_rt_conflict (rtx);static void vr4130_align_insns (void);static void mips_avoid_hazard (rtx, rtx, int *, rtx *, rtx);static void mips_avoid_hazards (void);static void mips_reorg (void);static bool mips_strict_matching_cpu_name_p (const char *, const char *);static bool mips_matching_cpu_name_p (const char *, const char *);static const struct mips_cpu_info *mips_parse_cpu (const char *, const char *);static const struct mips_cpu_info *mips_cpu_info_from_isa (int);static bool mips_return_in_memory (tree, tree);static bool mips_strict_argument_naming (CUMULATIVE_ARGS *);static void mips_macc_chains_record (rtx);static void mips_macc_chains_reorder (rtx *, int);static void vr4130_true_reg_dependence_p_1 (rtx, rtx, void *);static bool vr4130_true_reg_dependence_p (rtx);static bool vr4130_swap_insns_p (rtx, rtx);static void vr4130_reorder (rtx *, int);static void mips_promote_ready (rtx *, int, int);static int mips_sched_reorder (FILE *, int, rtx *, int *, int);static int mips_variable_issue (FILE *, int, rtx, int);static int mips_adjust_cost (rtx, rtx, rtx, int);static int mips_issue_rate (void);static int mips_multipass_dfa_lookahead (void);static void mips_init_libfuncs (void);static void mips_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode, tree, int *, int);static tree mips_build_builtin_va_list (void);static tree mips_gimplify_va_arg_expr (tree, tree, tree *, tree *);static bool mips_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode mode, tree, bool);static bool mips_callee_copies (CUMULATIVE_ARGS *, enum machine_mode mode, tree, bool);static int mips_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode mode, tree, bool);static bool mips_valid_pointer_mode (enum machine_mode);static bool mips_scalar_mode_supported_p (enum machine_mode);static bool mips_vector_mode_supported_p (enum machine_mode);static rtx mips_prepare_builtin_arg (enum insn_code, unsigned int, tree *);static rtx mips_prepare_builtin_target (enum insn_code, unsigned int, rtx);static rtx mips_expand_builtin (tree, rtx, rtx, enum machine_mode, int);static void mips_init_builtins (void);static rtx mips_expand_builtin_direct (enum insn_code, rtx, tree);static rtx mips_expand_builtin_movtf (enum mips_builtin_type, enum insn_code, enum mips_fp_condition, rtx, tree);static rtx mips_expand_builtin_compare (enum mips_builtin_type, enum insn_code, enum mips_fp_condition, rtx, tree);/* Structure to be filled in by compute_frame_size with register save masks, and offsets for the current function. */struct mips_frame_info GTY(()){ HOST_WIDE_INT total_size; /* # bytes that the entire frame takes up */ HOST_WIDE_INT var_size; /* # bytes that variables take up */ HOST_WIDE_INT args_size; /* # bytes that outgoing arguments take up */ HOST_WIDE_INT cprestore_size; /* # bytes that the .cprestore slot takes up */ HOST_WIDE_INT gp_reg_size; /* # bytes needed to store gp regs */ HOST_WIDE_INT fp_reg_size; /* # bytes needed to store fp regs */ unsigned int mask; /* mask of saved gp registers */ unsigned int fmask; /* mask of saved fp registers */ HOST_WIDE_INT gp_save_offset; /* offset from vfp to store gp registers */ HOST_WIDE_INT fp_save_offset; /* offset from vfp to store fp registers */ HOST_WIDE_INT gp_sp_offset; /* offset from new sp to store gp registers */ HOST_WIDE_INT fp_sp_offset; /* offset from new sp to store fp registers */ bool initialized; /* true if frame size already calculated */ int num_gp; /* number of gp registers saved */ int num_fp; /* number of fp registers saved */};struct machine_function GTY(()) { /* Pseudo-reg holding the value of $28 in a mips16 function which refers to GP relative global variables. */ rtx mips16_gp_pseudo_rtx; /* Current frame information, calculated by compute_frame_size. */ struct mips_frame_info frame; /* The register to use as the global pointer within this function. */ unsigned int global_pointer; /* True if mips_adjust_insn_length should ignore an instruction's hazard attribute. */ bool ignore_hazard_length_p; /* True if the whole function is suitable for .set noreorder and .set nomacro. */ bool all_noreorder_p; /* True if the function is known to have an instruction that needs $gp. */ bool has_gp_insn_p;};/* Information about a single argument. */struct mips_arg_info{ /* True if the argument is passed in a floating-point register, or
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -