📄 v850.c
字号:
/* Subroutines for insn-output.c for NEC V850 series Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. Contributed by Jeff Law (law@cygnus.com).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, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA. */#include "config.h"#include <stdio.h>#include <ctype.h>#include "tree.h"#include "rtl.h"#include "regs.h"#include "hard-reg-set.h"#include "real.h"#include "insn-config.h"#include "conditions.h"#include "insn-flags.h"#include "output.h"#include "insn-attr.h"#include "flags.h"#include "recog.h"#include "expr.h"#include "obstack.h"#include "toplev.h"#ifndef streq#define streq(a,b) (strcmp (a, b) == 0)#endif/* Function prototypes that cannot exist in v850.h due to dependency compilcations. */extern rtx function_arg PROTO ((CUMULATIVE_ARGS *, enum machine_mode, tree, int));extern int function_arg_partial_nregs PROTO ((CUMULATIVE_ARGS *, enum machine_mode, tree, int));extern void asm_file_start PROTO ((FILE *));extern void print_operand PROTO ((FILE *, rtx, int ));extern void print_operand_address PROTO ((FILE *, rtx));extern void v850_output_aligned_bss PROTO ((FILE *, tree, char *, int, int));extern void v850_output_common PROTO ((FILE *, tree, char *, int, int));extern void v850_output_local PROTO ((FILE *, tree, char *, int, int));extern int const_costs PROTO ((rtx, enum rtx_code));extern char * output_move_double PROTO ((rtx *));extern char * output_move_single PROTO ((rtx *));extern int ep_memory_operand PROTO ((rtx, enum machine_mode, int));extern int reg_or_0_operand PROTO ((rtx, enum machine_mode));extern int reg_or_int5_operand PROTO ((rtx, enum machine_mode));extern int call_address_operand PROTO ((rtx, enum machine_mode));extern int movsi_source_operand PROTO ((rtx, enum machine_mode));extern int power_of_two_operand PROTO ((rtx, enum machine_mode));extern int not_power_of_two_operand PROTO ((rtx, enum machine_mode));extern int special_symbolref_operand PROTO ((rtx, enum machine_mode));extern void v850_reorg PROTO ((rtx));extern void notice_update_cc PROTO ((rtx, rtx));extern int v850_valid_machine_decl_attribute PROTO ((tree, tree, tree));extern int v850_interrupt_function_p PROTO ((tree));extern int pattern_is_ok_for_prologue PROTO ((rtx, enum machine_mode));extern int pattern_is_ok_for_epilogue PROTO ((rtx, enum machine_mode));extern int register_is_ok_for_epilogue PROTO ((rtx, enum machine_mode));extern char * construct_save_jarl PROTO ((rtx));extern char * construct_restore_jr PROTO ((rtx));extern void v850_encode_data_area PROTO ((tree));extern void v850_set_default_decl_attr PROTO ((tree));/* Function prototypes for stupid compilers: */static void const_double_split PROTO ((rtx, HOST_WIDE_INT *, HOST_WIDE_INT *));static int const_costs_int PROTO ((HOST_WIDE_INT, int));static void substitute_ep_register PROTO ((rtx, rtx, int, int, rtx *, rtx *));static int push_data_area PROTO ((v850_data_area));static int pop_data_area PROTO ((v850_data_area));static int parse_ghs_pragma_token PROTO ((char *));static int ep_memory_offset PROTO ((enum machine_mode, int));static int mark_current_function_as_interrupt PROTO ((void));static void v850_set_data_area PROTO ((tree, v850_data_area));/* True if the current function has anonymous arguments. */int current_function_anonymous_args;/* Information about the various small memory areas. */struct small_memory_info small_memory[ (int)SMALL_MEMORY_max ] ={ /* name value max physical max */ { "tda", (char *)0, 0, 256 }, { "sda", (char *)0, 0, 65536 }, { "zda", (char *)0, 0, 32768 },};/* True if we don't need to check any more if the current function is an interrupt handler */static int v850_interrupt_cache_p = FALSE;/* Whether current function is an interrupt handler. */static int v850_interrupt_p = FALSE;/* Sometimes certain combinations of command options do not make sense on a particular target machine. You can define a macro `OVERRIDE_OPTIONS' to take account of this. This macro, if defined, is executed once just after all the command options have been parsed. Don't use this macro to turn on various extra optimizations for `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */voidoverride_options (){ int i; extern int atoi PROTO ((const char *)); /* Parse -m{s,t,z}da=nnn switches */ for (i = 0; i < (int)SMALL_MEMORY_max; i++) { if (small_memory[i].value) { if (!isdigit (*small_memory[i].value)) error ("%s=%s is not numeric.", small_memory[i].name, small_memory[i].value); else { small_memory[i].max = atoi (small_memory[i].value); if (small_memory[i].max > small_memory[i].physical_max) error ("%s=%s is too large.", small_memory[i].name, small_memory[i].value); } } }}/* Output assembly code for the start of the file. */voidasm_file_start (file) FILE *file;{ output_file_directive (file, main_input_filename);}/* Return an RTX to represent where a value with mode MODE will be returned from a function. If the result is 0, the argument is pushed. */rtxfunction_arg (cum, mode, type, named) CUMULATIVE_ARGS *cum; enum machine_mode mode; tree type; int named;{ rtx result = 0; int size, align; if (TARGET_GHS && !named) return NULL_RTX; if (mode == BLKmode) size = int_size_in_bytes (type); else size = GET_MODE_SIZE (mode); if (type) align = TYPE_ALIGN (type) / BITS_PER_UNIT; else align = size; cum->nbytes = (cum->nbytes + align - 1) &~(align - 1); if (cum->nbytes > 4 * UNITS_PER_WORD) return 0; if (type == NULL_TREE && cum->nbytes + size > 4 * UNITS_PER_WORD) return 0; switch (cum->nbytes / UNITS_PER_WORD) { case 0: result = gen_rtx (REG, mode, 6); break; case 1: result = gen_rtx (REG, mode, 7); break; case 2: result = gen_rtx (REG, mode, 8); break; case 3: result = gen_rtx (REG, mode, 9); break; default: result = 0; } return result;}/* Return the number of words which must be put into registers for values which are part in registers and part in memory. */intfunction_arg_partial_nregs (cum, mode, type, named) CUMULATIVE_ARGS *cum; enum machine_mode mode; tree type; int named;{ int size, align; if (TARGET_GHS && !named) return 0; if (mode == BLKmode) size = int_size_in_bytes (type); else size = GET_MODE_SIZE (mode); if (type) align = TYPE_ALIGN (type) / BITS_PER_UNIT; else align = size; cum->nbytes = (cum->nbytes + align - 1) &~(align - 1); if (cum->nbytes > 4 * UNITS_PER_WORD) return 0; if (cum->nbytes + size <= 4 * UNITS_PER_WORD) return 0; if (type == NULL_TREE && cum->nbytes + size > 4 * UNITS_PER_WORD) return 0; return (4 * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD;}/* Return the high and low words of a CONST_DOUBLE */static voidconst_double_split (x, p_high, p_low) rtx x; HOST_WIDE_INT *p_high; HOST_WIDE_INT *p_low;{ if (GET_CODE (x) == CONST_DOUBLE) { long t[2]; REAL_VALUE_TYPE rv; switch (GET_MODE (x)) { case DFmode: REAL_VALUE_FROM_CONST_DOUBLE (rv, x); REAL_VALUE_TO_TARGET_DOUBLE (rv, t); *p_high = t[1]; /* since v850 is little endian */ *p_low = t[0]; /* high is second word */ return; case SFmode: REAL_VALUE_FROM_CONST_DOUBLE (rv, x); REAL_VALUE_TO_TARGET_SINGLE (rv, *p_high); *p_low = 0; return; case VOIDmode: case DImode: *p_high = CONST_DOUBLE_HIGH (x); *p_low = CONST_DOUBLE_LOW (x); return; default: break; } } fatal_insn ("const_double_split got a bad insn:", x);}/* Return the cost of the rtx R with code CODE. */static intconst_costs_int (value, zero_cost) HOST_WIDE_INT value; int zero_cost;{ if (CONST_OK_FOR_I (value)) return zero_cost; else if (CONST_OK_FOR_J (value)) return 1; else if (CONST_OK_FOR_K (value)) return 2; else return 4;}intconst_costs (r, c) rtx r; enum rtx_code c;{ HOST_WIDE_INT high, low; switch (c) { case CONST_INT: return const_costs_int (INTVAL (r), 0); case CONST_DOUBLE: const_double_split (r, &high, &low); if (GET_MODE (r) == SFmode) return const_costs_int (high, 1); else return const_costs_int (high, 1) + const_costs_int (low, 1); case SYMBOL_REF: case LABEL_REF: case CONST: return 2; case HIGH: return 1; default: return 4; }}/* Print operand X using operand code CODE to assembly language output file FILE. */voidprint_operand (file, x, code) FILE *file; rtx x; int code;{ HOST_WIDE_INT high, low; switch (code) { case 'c': /* We use 'c' operands with symbols for .vtinherit */ if (GET_CODE (x) == SYMBOL_REF) { output_addr_const(file, x); break; } /* fall through */ case 'b': case 'B': case 'C': switch ((code == 'B' || code == 'C') ? reverse_condition (GET_CODE (x)) : GET_CODE (x)) { case NE: if (code == 'c' || code == 'C') fprintf (file, "nz"); else fprintf (file, "ne"); break; case EQ: if (code == 'c' || code == 'C') fprintf (file, "z"); else fprintf (file, "e"); break; case GE: fprintf (file, "ge"); break; case GT: fprintf (file, "gt"); break; case LE: fprintf (file, "le"); break; case LT: fprintf (file, "lt"); break; case GEU: fprintf (file, "nl"); break; case GTU: fprintf (file, "h"); break; case LEU: fprintf (file, "nh"); break; case LTU: fprintf (file, "l"); break; default: abort (); } break; case 'F': /* high word of CONST_DOUBLE */ if (GET_CODE (x) == CONST_INT) fprintf (file, "%d", (INTVAL (x) >= 0) ? 0 : -1); else if (GET_CODE (x) == CONST_DOUBLE) { const_double_split (x, &high, &low); fprintf (file, "%ld", (long) high); } else abort (); break; case 'G': /* low word of CONST_DOUBLE */ if (GET_CODE (x) == CONST_INT) fprintf (file, "%ld", (long) INTVAL (x)); else if (GET_CODE (x) == CONST_DOUBLE) { const_double_split (x, &high, &low); fprintf (file, "%ld", (long) low); } else abort (); break; case 'L': fprintf (file, "%d\n", INTVAL (x) & 0xffff); break; case 'M': fprintf (file, "%d", exact_log2 (INTVAL (x))); break; case 'O': if (special_symbolref_operand (x, VOIDmode)) { char* name; if (GET_CODE (x) == SYMBOL_REF) name = XSTR (x, 0); else if (GET_CODE (x) == CONST) name = XSTR (XEXP (XEXP (x, 0), 0), 0); else abort (); if (ZDA_NAME_P (name)) fprintf (file, "zdaoff"); else if (SDA_NAME_P (name)) fprintf (file, "sdaoff"); else if (TDA_NAME_P (name)) fprintf (file, "tdaoff"); else abort (); } else abort (); break; case 'P': if (special_symbolref_operand (x, VOIDmode)) output_addr_const (file, x); else abort (); break; case 'Q': if (special_symbolref_operand (x, VOIDmode)) { char* name; if (GET_CODE (x) == SYMBOL_REF) name = XSTR (x, 0); else if (GET_CODE (x) == CONST) name = XSTR (XEXP (XEXP (x, 0), 0), 0); else abort (); if (ZDA_NAME_P (name)) fprintf (file, "r0"); else if (SDA_NAME_P (name)) fprintf (file, "gp"); else if (TDA_NAME_P (name)) fprintf (file, "ep"); else abort (); } else abort (); break; case 'R': /* 2nd word of a double. */ switch (GET_CODE (x)) { case REG: fprintf (file, reg_names[REGNO (x) + 1]); break; case MEM: print_operand_address (file, XEXP (adj_offsettable_operand (x, 4), 0)); break; default: break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -