[28e18d]: Backend / If1opt / callreorder.c  Maximize  Restore  History

Download this file

193 lines (164 with data), 5.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/**************************************************************************/
/* FILE ************** callreorder.c ************************/
/**************************************************************************/
/* Author: Dave Cann */
/* Update: Patrick Miller -- Ansi support (Dec 2000) */
/* Copyright (C) University of California Regents */
/**************************************************************************/
/*
* $Log:
*/
/**************************************************************************/
#include "world.h"
PNODE SortedTree;
static PNODE FindNewFunctionGraph( nm )
char *nm;
{
register PNODE g;
for ( g = SortedTree; g != NULL; g = g->gsucc ) {
if ( strcmp( g->G_NAME, nm ) == 0 ) return( g );
}
return( NULL );
}
static PNODE FindTheFunction( nm )
char *nm;
{
register PNODE g;
for ( g = SortedTree; g != NULL; g = g->gsucc ) {
if ( strcmp( g->G_NAME, nm ) == 0 ) return( g );
}
for ( g = glstop->gsucc; g != NULL; g = g->gsucc ) {
if ( strcmp( g->G_NAME, nm ) == 0 ) return( g );
}
return( NULL );
}
static int InSortedTree( f,g )
PNODE f;
PNODE g;
{
register PNODE n;
register PNODE sg;
for ( n = g->G_NODES; n != NULL; n = n->nsucc ) {
if ( IsCompound( n ) ) {
for ( sg = n->C_SUBS; sg != NULL; sg = sg->gsucc ) {
if ( !InSortedTree( f,sg ) ) return FALSE;
}
}
if ( IsCall( n ) && strcmp(n->imp->CoNsT,f->G_NAME) != 0 ) {
if ( !FindNewFunctionGraph( n->imp->CoNsT ) ) return FALSE;
}
}
return TRUE;
}
static int CallReachable( f,g )
PNODE f;
PNODE g;
{
register PNODE n;
register PNODE sg;
register PNODE ff;
for ( n = g->G_NODES; n != NULL; n = n->nsucc ) {
if ( IsCompound( n ) ) {
for (sg = n->C_SUBS; sg != NULL; sg = sg->gsucc) {
if (CallReachable(f,sg)) return TRUE;
}
}
if ( IsCall(n) ) {
ff = FindTheFunction(n->imp->CoNsT);
if ( !ff->checked ) {
ff->checked = TRUE;
if (ff==f || CallReachable(f,ff)) return TRUE;
}
}
}
return FALSE;
}
static int InRecursiveChain(F)
PNODE F;
{
PNODE ff;
/* ------------------------------------------------------------ */
/* Set all uncommitted functions as unmarked */
/* ------------------------------------------------------------ */
for(ff=glstop->gsucc; ff; ff=ff->gsucc) ff->checked = FALSE;
/* ------------------------------------------------------------ */
/* Look for a cycle that contains F */
/* ------------------------------------------------------------ */
return CallReachable(F,F);
}
/**************************************************************************/
/* GLOBAL ************** CallReorder ************************/
/************************************************************************ **/
/* PURPOSE: */
/**************************************************************************/
void CallReorder()
{
register PNODE f,next,last;
SortedTree = NULL;
while ( glstop->gsucc ) {
for ( f = glstop->gsucc; f; f = next ) {
next = f->gsucc;
if ( InSortedTree(f,f) || InRecursiveChain(f) ) {
/* ------------------------------------------------------------ */
/* Unlink node from glstop list */
/* ------------------------------------------------------------ */
f->gpred->gsucc = next;
if ( next ) next->gpred = f->gpred;
/* ------------------------------------------------------------ */
/* Add it to SortedTree list */
/* ------------------------------------------------------------ */
f->gsucc = SortedTree;
SortedTree = f;
f->checked = TRUE; /* Helps speed up InRecursiveChain */
}
}
}
/* ------------------------------------------------------------ */
/* Relink the sorted calls onto the glstop list */
/* ------------------------------------------------------------ */
glstop->gpred = SortedTree;
last = (PNODE)NULL;
for(f = SortedTree; f; f = next) {
next = f->gsucc;
f->gsucc = last;
f->gpred = next;
glstop->gsucc = f;
last = f;
}
last->gpred = glstop;
}
/* $Log$
/* Revision 1.2 2001/01/01 05:46:22 patmiller
/* Adding prototypes and header info -- all will be broken
/*
/* Revision 1.1.1.1 2000/12/31 17:56:10 patmiller
/* Well, here is the first set of big changes in the distribution
/* in 5 years! Right now, I did a lot of work on configuration/
/* setup (now all autoconf), breaking out the machine dependent
/* #ifdef's (with a central acconfig.h driven config file), changed
/* the installation directories to be more gnu style /usr/local
/* (putting data in the /share/sisal14 dir for instance), and
/* reduced the footprint in the top level /usr/local/xxx hierarchy.
/*
/* I also wrote a new compiler tool (sisalc) to replace osc. I
/* found that the old logic was too convoluted. This does NOT
/* replace the full functionality, but then again, it doesn't have
/* 300 options on it either.
/*
/* Big change is making the code more portably correct. It now
/* compiles under gcc -ansi -Wall mostly. Some functions are
/* not prototyped yet.
/*
/* Next up: Full prototypes (little) checking out the old FLI (medium)
/* and a new Frontend for simpler extension and a new FLI (with clean
/* C, C++, F77, and Python! support).
/*
/* Pat
/*
/*
* Revision 1.2 1994/04/15 15:50:29 denton
* Added config.h to centralize machine specific header files.
*
* Revision 1.1 1993/11/30 00:26:23 miller
* Call reordering for recursive call with record bug.
* */

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks