home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
gnu
/
gcc-2.3.3-src.lha
/
GNU
/
src
/
amiga
/
gcc-2.3.3
/
stupid.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-06
|
17KB
|
545 lines
/* Dummy data flow analysis for GNU compiler in nonoptimizing mode.
Copyright (C) 1987, 1991 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* This file performs stupid register allocation, which is used
when cc1 gets the -noreg switch (which is when cc does not get -O).
Stupid register allocation goes in place of the the flow_analysis,
local_alloc and global_alloc passes. combine_instructions cannot
be done with stupid allocation because the data flow info that it needs
is not computed here.
In stupid allocation, the only user-defined variables that can
go in registers are those declared "register". They are assumed
to have a life span equal to their scope. Other user variables
are given stack slots in the rtl-generation pass and are not
represented as pseudo regs. A compiler-generated temporary
is assumed to live from its first mention to its last mention.
Since each pseudo-reg's life span is just an interval, it can be
represented as a pair of numbers, each of which identifies an insn by
its position in the function (number of insns before it). The first
thing done for stupid allocation is to compute such a number for each
insn. It is called the suid. Then the life-interval of each
pseudo reg is computed. Then the pseudo regs are ordered by priority
and assigned hard regs in priority order. */
#include <stdio.h>
#include "config.h"
#include "rtl.h"
#include "hard-reg-set.h"
#include "regs.h"
#include "flags.h"
/* Vector mapping INSN_UIDs to suids.
The suids are like uids but increase monotonically always.
We use them to see whether a subroutine call came
between a variable's birth and its death. */
static int *uid_suid;
/* Get the suid of an insn. */
#define INSN_SUID(INSN) (uid_suid[INSN_UID (INSN)])
/* Record the suid of the last CALL_INSN
so we can tell whether a pseudo reg crosses any calls. */
static int last_call_suid;
/* Record the suid of the last JUMP_INSN
so we can tell whether a pseudo reg crosses any jumps. */
static int last_jump_suid;
/* Record the suid of the last CODE_LABEL
so we can tell whether a pseudo reg crosses any labels. */
static int last_label_suid;
/* Element N is suid of insn where life span of pseudo reg N ends.
Element is 0 if register N has not been seen yet on backward scan. */
static int *reg_where_dead;
/* Element N is suid of insn where life span of pseudo reg N begins. */
static int *reg_where_born;
/* Element N is 1 if pseudo reg N lives across labels or jumps. */
static char *reg_crosses_blocks;
/* Numbers of pseudo-regs to be allocated, highest priority first. */
static int *reg_order;
/* Indexed by reg number (hard or pseudo), nonzero if register is live
at the current point in the instruction stream. */
static char *regs_live;
/* Indexed by insn's suid, the set of hard regs live after that insn. */
static HARD_REG_SET *after_insn_hard_regs;
/* Record that hard reg REGNO is live after insn INSN. */
#define MARK_LIVE_AFTER(INSN,REGNO) \
SET_HARD_REG_BIT (after_insn_hard_regs[INSN_SUID (INSN)], (REGNO))
static void stupid_mark_refs ();
static int stupid_reg_compare ();
static int stupid_find_reg ();
/* Stupid life analysis is for the case where only variables declared
`register' go in registers. For this case, we mark all
pseudo-registers that belong to register variables as
dying in the last instruction of the function, and all other
pseudo registers as dying in the last place they are referenced.
Hard registers are marked as dying in the last reference before
the end or before each store into them. */
void
stupid_life_analysis (f, nregs, file)
rtx f;
int nregs;
FILE *file;
{
register int i;
register rtx last, insn;
int max_uid;
bzero (regs_ever_live, sizeof regs_ever_live);
regs_live = (char *) alloca (nregs);
/* First find the last real insn, and count the number of insns,
and assign insns their suids. */
for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
if (INSN_UID (insn) > i)
i = INSN_UID (insn);
max_uid = i + 1;
uid_suid = (int *) alloca ((i + 1) * sizeof (int));
/* Compute the mapping from uids to suids.
Suids are numbers assigned to insns, like uids,
except that suids increase monotonically through the code. */
last = 0; /* In case of empty function body */
for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
{
if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
|| GET_CODE (insn) == JUMP_INSN)
last = insn;
INSN_SUID (insn) = ++i;
}
last_call_suid = i + 1;
last_jump_suid = i + 1;
last_label_suid = i + 1;
max_regno = nregs;
/* Allocate tables to record info about regs. */
reg_where_dead = (int *) alloca (nregs * sizeof (int));
bzero (reg_where_dead, nregs * sizeof (int));
reg_where_born = (int *) alloca (nregs * sizeof (int));
bzero (reg_where_born, nregs * sizeof (int));
reg_crosses_blocks = (char *) alloca (nregs);
bzero (reg_crosses_blocks, nregs);
reg_order = (int *) alloca (nregs * sizeof (int));
bzero (reg_order, nregs * sizeof (int));
reg_renumber = (short *) oballoc (nregs * sizeof (short));
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
reg_renumber[i] = i;
for (i = FIRST_VIRTUAL_REGISTER; i <= LAST_VIRTUAL_REGISTER; i++)
reg_renumber[i] = -1;
after_insn_hard_regs = (HARD_REG_SET *) alloca (max_uid * sizeof (HARD_REG_SET));
bzero (after_insn_hard_regs, max_uid * sizeof (HARD_REG_SET));
/* Allocate and zero out many data structures
that will record the data from lifetime analysis. */
allocate_for_life_analysis ();
for (i = 0; i < max_regno; i++)
{
reg_n_deaths[i] = 1;
}
bzero (regs_live, nregs);
/* Find where each pseudo register is born and dies,
by scanning all insns from the end to the start
and noting all mentions of the registers.
Also find where each hard register is live
and record that info in after_insn_hard_regs.
regs_live[I] is 1 if hard reg I is live
at the current point in the scan. */
for (insn = last; insn; insn = PREV_INSN (insn))
{
register HARD_REG_SET *p = after_insn_hard_regs + INSN_SUID (insn);
/* Copy the info in regs_live
into the element of after_insn_hard_regs
for the current position in the rtl code. */
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
if (regs_live[i])
SET_HARD_REG_BIT (*p, i);
/* Mark all call-clobbered regs as live after each call insn
so that a pseudo whose life span includes this insn
will not go in one of them.
Then mark those regs as all dead for the continuing scan
of the insns before the call. */
if (GET_CODE (insn) == CALL_INSN)
{
last_call_suid = INSN_SUID (insn);
IOR_HARD_REG_SET (after_insn_hard_regs[last_call_suid],
call_used_reg_set);
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
if (call_used_regs[i])
regs_live[i] = 0;
}
if (GET_CODE (insn) == JUMP_INSN)
last_jump_suid = INSN_SUID (insn);
if (GET_CODE (insn) == CODE_LABEL)
last_label_suid = INSN_SUID (insn);
/* Update which hard regs are currently live
and also the birth and death suids of pseudo regs
based on the pattern of this insn. */
if (GET_CODE (insn) == INSN
|| GET_CODE (insn) == CALL_INSN
|| GET_CODE (insn) == JUMP_INSN)
{
stupid_mark_refs (PATTERN (insn), insn);
}
}
/* Now decide the order in which