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

📄 final.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Convert RTL to assembler code and output it, for GNU compiler.   Copyright (C) 1987, 1988, 1989, 1992 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, 675 Mass Ave, Cambridge, MA 02139, USA.  *//* This is the final pass of the compiler.   It looks at the rtl code for a function and outputs assembler code.   Call `final_start_function' to output the assembler code for function entry,   `final' to output assembler code for some RTL code,   `final_end_function' to output assembler code for function exit.   If a function is compiled in several pieces, each piece is   output separately with `final'.   Some optimizations are also done at this level.   Move instructions that were made unnecessary by good register allocation   are detected and omitted from the output.  (Though most of these   are removed by the last jump pass.)   Instructions to set the condition codes are omitted when it can be   seen that the condition codes already had the desired values.   In some cases it is sufficient if the inherited condition codes   have related values, but this may require the following insn   (the one that tests the condition codes) to be modified.   The code for the function prologue and epilogue are generated   directly as assembler code by the macros FUNCTION_PROLOGUE and   FUNCTION_EPILOGUE.  Those instructions never exist as rtl.  */#include "config.h"#include "gvarargs.h"#include "rtl.h"#include "regs.h"#include "insn-config.h"#include "insn-flags.h"#include "insn-attr.h"#include "insn-codes.h"#include "recog.h"#include "conditions.h"#include "flags.h"#include "real.h"#include "hard-reg-set.h"#include "defaults.h"#include <stdio.h>#include "output.h"/* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist.  */#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)#if defined (USG) || defined (NO_STAB_H)#include "gstab.h"  /* If doing DBX on sysV, use our own stab.h.  */#else#include <stab.h>  /* On BSD, use the system's stab.h.  */#endif /* not USG */#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */#ifdef XCOFF_DEBUGGING_INFO#include "xcoffout.h"#endif/* .stabd code for line number.  */#ifndef N_SLINE#define	N_SLINE	0x44#endif/* .stabs code for included file name.  */#ifndef N_SOL#define	N_SOL 0x84#endif#ifndef INT_TYPE_SIZE#define INT_TYPE_SIZE BITS_PER_WORD#endif/* If we aren't using cc0, CC_STATUS_INIT shouldn't exist.  So define a   null default for it to save conditionalization later.  */#ifndef CC_STATUS_INIT#define CC_STATUS_INIT#endif/* How to start an assembler comment.  */#ifndef ASM_COMMENT_START#define ASM_COMMENT_START ";#"#endifrtx peephole ();void output_asm_insn ();rtx alter_subreg ();static int alter_cond ();void output_asm_label ();static void output_operand ();void output_address ();void output_addr_const ();static void output_source_line ();rtx final_scan_insn ();void profile_function ();static void profile_after_prologue ();#ifdef HAVE_ATTR_lengthstatic int asm_insn_count ();#endif/* Nonzero means this function is a leaf function, with no function calls.    This variable exists to be examined in FUNCTION_PROLOGUE   and FUNCTION_EPILOGUE.  Always zero, unless set by some action.  */int leaf_function;int leaf_function_p ();#ifdef LEAF_REGISTERSint only_leaf_regs_used ();static void leaf_renumber_regs ();void leaf_renumber_regs_insn ();#endif/* Last insn processed by final_scan_insn.  */static rtx debug_insn = 0;/* Line number of last NOTE.  */static int last_linenum;/* Number of basic blocks seen so far;   used if profile_block_flag is set.  */static int count_basic_blocks;/* Nonzero while outputting an `asm' with operands.   This means that inconsistencies are the user's fault, so don't abort.   The precise value is the insn being output, to pass to error_for_asm.  */static rtx this_is_asm_operands;/* Number of operands of this insn, for an `asm' with operands.  */static int insn_noperands;/* Compare optimization flag.  */static rtx last_ignored_compare = 0;/* Flag indicating this insn is the start of a new basic block.  */static int new_block = 1;/* All the symbol-blocks (levels of scoping) in the compilation   are assigned sequence numbers in order of appearance of the   beginnings of the symbol-blocks.  Both final and dbxout do this,   and assume that they will both give the same number to each block.   Final uses these sequence numbers to generate assembler label names   LBBnnn and LBEnnn for the beginning and end of the symbol-block.   Dbxout uses the sequence numbers to generate references to the same labels   from the dbx debugging information.   Sdb records this level at the beginning of each function,   in order to find the current level when recursing down declarations.   It outputs the block beginning and endings   at the point in the asm file where the blocks would begin and end.  */int next_block_index;/* Assign a unique number to each insn that is output.   This can be used to generate unique local labels.  */static int insn_counter = 0;#ifdef HAVE_cc0/* This variable contains machine-dependent flags (defined in tm.h)   set and examined by output routines   that describe how to interpret the condition codes properly.  */CC_STATUS cc_status;/* During output of an insn, this contains a copy of cc_status   from before the insn.  */CC_STATUS cc_prev_status;#endif/* Indexed by hardware reg number, is 1 if that register is ever   used in the current function.   In life_analysis, or in stupid_life_analysis, this is set   up to record the hard regs used explicitly.  Reload adds   in the hard regs used for holding pseudo regs.  Final uses   it to generate the code in the function prologue and epilogue   to save and restore registers as needed.  */char regs_ever_live[FIRST_PSEUDO_REGISTER];/* Nonzero means current function must be given a frame pointer.   Set in stmt.c if anything is allocated on the stack there.   Set in reload1.c if anything is allocated on the stack there.  */int frame_pointer_needed;/* Assign unique numbers to labels generated for profiling.  */int profile_label_no;/* Length so far allocated in PENDING_BLOCKS.  */static int max_block_depth;/* Stack of sequence numbers of symbol-blocks of which we have seen the   beginning but not yet the end.  Sequence numbers are assigned at   the beginning; this stack allows us to find the sequence number   of a block that is ending.  */static int *pending_blocks;/* Number of elements currently in use in PENDING_BLOCKS.  */static int block_depth;/* Nonzero if have enabled APP processing of our assembler output.  */static int app_on;/* If we are outputting an insn sequence, this contains the sequence rtx.   Zero otherwise.  */rtx final_sequence;/* Indexed by line number, nonzero if there is a note for that line.  */static char *line_note_exists;/* Initialize data in final at the beginning of a compilation.  */voidinit_final (filename)     char *filename;{  next_block_index = 2;  app_on = 0;  max_block_depth = 20;  pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);  final_sequence = 0;}/* Called at end of source file,   to output the block-profiling table for this entire compilation.  */voidend_final (filename)     char *filename;{  int i;  if (profile_block_flag)    {      char name[12];      data_section ();      /* Output the main header, of 6 words:	 0:  1 if this file's initialized, else 0.	 1:  address of file name.	 2:  address of table of counts.	 4:  number of counts in the table.	 5:  always 0, for compatibility with Sun.	 6:  extra word added by GNU: address of address table	      which contains addresses of basic blocks,	      in parallel with the table of counts.  */      ASM_OUTPUT_ALIGN (asm_out_file,			exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT));      ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);      assemble_integer (const0_rtx, UNITS_PER_WORD, 1);      ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);      assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);      ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);      assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);      assemble_integer (GEN_INT (count_basic_blocks), UNITS_PER_WORD, 1);      assemble_integer (const0_rtx, UNITS_PER_WORD, 1);      ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);      assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);      /* Output the file name.  */      ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);      {	int len = strlen (filename);	char *data_file = (char *) alloca (len + 3);	strcpy (data_file, filename);	strip_off_ending (data_file, len);	strcat (data_file, ".d");	assemble_string (data_file, strlen (data_file) + 1);      }      /* Realign data section.  */      ASM_OUTPUT_ALIGN (asm_out_file,			exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT));      /* Make space for the table of counts.  */      ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);      assemble_zeros (INT_TYPE_SIZE / BITS_PER_UNIT * count_basic_blocks);      /* Output the table of addresses.  */      readonly_data_section ();      /* Realign in new section */      ASM_OUTPUT_ALIGN (asm_out_file,			floor_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT));      ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);      for (i = 0; i < count_basic_blocks; i++)	{	  char name[12];	  ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);	  assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),			    UNITS_PER_WORD, 1);	}      /* End with the address of the table of addresses,	 so we can find it easily, as the last word in the file's text.  */      ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);      assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);    }}/* Enable APP processing of subsequent output.   Used before the output from an `asm' statement.  */voidapp_enable (){  if (! app_on)    {      fprintf (asm_out_file, ASM_APP_ON);      app_on = 1;    }}/* Enable APP processing of subsequent output.   Called from varasm.c before most kinds of output.  */voidapp_disable (){  if (app_on)    {      fprintf (asm_out_file, ASM_APP_OFF);      app_on = 0;    }}/* Return the number of slots filled in the current    delayed branch sequence (we don't count the insn needing the   delay slot).   Zero if not in a delayed branch sequence.  */#ifdef DELAY_SLOTSintdbr_sequence_length (){  if (final_sequence != 0)    return XVECLEN (final_sequence, 0) - 1;  else    return 0;}#endif/* The next two pages contain routines used to compute the length of an insn   and to shorten branches.  *//* Arrays for insn lengths, and addresses.  The latter is referenced by   `insn_current_length'.  */static short *insn_lengths;int *insn_addresses;/* Address of insn being processed.  Used by `insn_current_length'.  */int insn_current_address;/* Indicate the branch shortening hasn't yet been done.  */voidinit_insn_lengths (){  insn_lengths = 0;}/* Obtain the current length of an insn.  If branch shortening has been done,   get its actual length.  Otherwise, get its maximum length.  */intget_attr_length (insn)     rtx insn;{#ifdef HAVE_ATTR_length  rtx body;  int i;  int length = 0;  if (insn_lengths)    return insn_lengths[INSN_UID (insn)];  else    switch (GET_CODE (insn))      {      case NOTE:      case BARRIER:      case CODE_LABEL:	return 0;      case CALL_INSN:	length = insn_default_length (insn);	break;      case JUMP_INSN:	body = PATTERN (insn);        if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)	  {	    /* This only takes room if jump tables go into the text section.  */#if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)	    length = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)		      * GET_MODE_SIZE (GET_MODE (body)));	    /* Be pessimistic and assume worst-case alignment.  */	    length += (GET_MODE_SIZE (GET_MODE (body)) - 1);#else	    return 0;#endif	  }	else	  length = insn_default_length (insn);	break;      case INSN:	body = PATTERN (insn);	if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)	  return 0;	else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)	  length = asm_insn_count (insn) * insn_default_length (insn);	else if (GET_CODE (body) == SEQUENCE)	  for (i = 0; i < XVECLEN (body, 0); i++)	    length += get_attr_length (XVECEXP (body, 0, i));	else	  length = insn_default_length (insn);      }#ifdef ADJUST_INSN_LENGTH  ADJUST_INSN_LENGTH (insn, length);#endif  return length;#else /* not HAVE_ATTR_length */  return 0;#endif /* not HAVE_ATTR_length */}/* Make a pass over all insns and compute their actual lengths by shortening   any branches of variable length if possible.  *//* Give a default value for the lowest address in a function.  */#ifndef FIRST_INSN_ADDRESS#define FIRST_INSN_ADDRESS 0#endifvoidshorten_branches (first)     rtx first;{#ifdef HAVE_ATTR_length  rtx insn;  int something_changed = 1;  int max_uid = 0;  char *varying_length;  rtx body;  int uid;  /* Compute maximum UID and allocate arrays.  */  for (insn = first; insn; insn = NEXT_INSN (insn))    if (INSN_UID (insn) > max_uid)

⌨️ 快捷键说明

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