📄 emit-rtl.c
字号:
/* Emit RTL for the GNU C-Compiler expander. Copyright (C) 1987, 88, 92, 93, 94, 1995 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, 59 Temple Place - Suite 330,Boston, MA 02111-1307, 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"#ifdef __STDC__#include <stdarg.h>#else#include <varargs.h>#endif#include "rtl.h"#include "tree.h"#include "flags.h"#include "function.h"#include "expr.h"#include "regs.h"#include "insn-config.h"#include "real.h"#include "obstack.h"#include "bytecode.h"#include "machmode.h"#include "bc-opcode.h"#include "bc-typecd.h"#include "bc-optab.h"#include "bc-emit.h"#include <stdio.h>/* Opcode names */#ifdef BCDEBUG_PRINT_CODEchar *opcode_name[] ={#include "bc-opname.h""***END***"};#endif/* Commonly used modes. */enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */enum machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. *//* 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. When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little tricky: until register elimination has taken place hard_frame_pointer_rtx should be used if it is being set, and frame_pointer_rtx otherwise. After register elimination hard_frame_pointer_rtx should always be used. On machines where the two registers are same (most) then these are the same. 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 hard_frame_pointer_rtx; /* (REG:Pmode HARD_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' along with `sequence_rtl_expr' and then starts a new, nested sequence of insns. */static rtx first_insn = NULL;static rtx last_insn = NULL;/* RTL_EXPR within which the current sequence will be placed. Use to prevent reuse of any temporaries within the sequence until after the RTL_EXPR is emitted. */tree sequence_rtl_expr = 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 ();extern struct obstack *rtl_obstack;extern int stack_depth;extern int max_stack_depth;/* 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 VPROTO((enum rtx_code code, enum machine_mode mode, ...)){#ifndef __STDC__ enum rtx_code code; enum machine_mode mode;#endif va_list p; register int i; /* Array indices... */ register char *fmt; /* Current rtx's format... */ register rtx rt_val; /* RTX to return to caller... */ VA_START (p, mode);#ifndef __STDC__ code = va_arg (p, enum rtx_code); mode = va_arg (p, enum machine_mode);#endif 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 != HARD_FRAME_POINTER_REGNUM if (hard_frame_pointer_rtx && regno == HARD_FRAME_POINTER_REGNUM && mode == Pmode && ! reload_in_progress) return hard_frame_pointer_rtx;#endif#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_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 VPROTO((int n, ...)){#ifndef __STDC__ int n;#endif int i; va_list p; rtx *vector; VA_START (p, n);#ifndef __STDC__ n = va_arg (p, int);#endif 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -