X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gprof%2Fcg_dfn.c;h=1da4c66b84f215b80774f5ed12ba5d5d289ab015;hb=abdb711e0855f0597a96db0486b598144b788212;hp=29eb64c64b061d83e83779b3a08797d8c925e22d;hpb=12516a373c27abe4516c2a3c84cfe9d94f02e18f;p=deliverable%2Fbinutils-gdb.git diff --git a/gprof/cg_dfn.c b/gprof/cg_dfn.c index 29eb64c64b..1da4c66b84 100644 --- a/gprof/cg_dfn.c +++ b/gprof/cg_dfn.c @@ -1,29 +1,41 @@ /* - * Copyright (c) 1983 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. * - * Redistribution and use in source and binary forms are permitted - * provided that: (1) source distributions retain this entire copyright - * notice and comment, and (2) distributions including binaries display - * the following acknowledgement: ``This product includes software - * developed by the University of California, Berkeley and its contributors'' - * in the documentation or other materials provided with the distribution - * and in all advertising materials mentioning features or use of this - * software. Neither the name of the University nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ -#include #include "gprof.h" +#include "libiberty.h" +#include "search_list.h" +#include "source.h" +#include "symtab.h" #include "cg_arcs.h" #include "cg_dfn.h" -#include "symtab.h" #include "utils.h" -#define DFN_DEPTH 100 +#define DFN_INCR_DEPTH (128) typedef struct { @@ -32,7 +44,14 @@ typedef struct } DFN_Stack; -DFN_Stack dfn_stack[DFN_DEPTH]; +static bfd_boolean is_numbered (Sym *); +static bfd_boolean is_busy (Sym *); +static void find_cycle (Sym *); +static void pre_visit (Sym *); +static void post_visit (Sym *); + +DFN_Stack *dfn_stack = NULL; +int dfn_maxdepth = 0; int dfn_depth = 0; int dfn_counter = DFN_NAN; @@ -40,25 +59,25 @@ int dfn_counter = DFN_NAN; /* * Is CHILD already numbered? */ -static bool -DEFUN (is_numbered, (child), Sym * child) +static bfd_boolean +is_numbered (Sym *child) { return child->cg.top_order != DFN_NAN && child->cg.top_order != DFN_BUSY; -} /* is_numbered */ +} /* * Is CHILD already busy? */ -static bool -DEFUN (is_busy, (child), Sym * child) +static bfd_boolean +is_busy (Sym *child) { if (child->cg.top_order == DFN_NAN) { return FALSE; - } /* if */ + } return TRUE; -} /* is_busy */ +} /* @@ -68,12 +87,12 @@ DEFUN (is_busy, (child), Sym * child) * depth-first number). */ static void -DEFUN (find_cycle, (child), Sym * child) +find_cycle (Sym *child) { Sym *head = 0; Sym *tail; int cycle_top; - int index; + int cycle_index; for (cycle_top = dfn_depth; cycle_top > 0; --cycle_top) { @@ -81,17 +100,17 @@ DEFUN (find_cycle, (child), Sym * child) if (child == head) { break; - } /* if */ + } if (child->cg.cyc.head != child && child->cg.cyc.head == head) { break; - } /* if */ - } /* for */ + } + } if (cycle_top <= 0) { fprintf (stderr, "[find_cycle] couldn't find head of cycle\n"); done (1); - } /* if */ + } #ifdef DEBUG if (debug_level & DFNDEBUG) { @@ -104,7 +123,7 @@ DEFUN (find_cycle, (child), Sym * child) else { printf (""); - } /* if */ + } printf ("\n"); } #endif @@ -137,7 +156,7 @@ DEFUN (find_cycle, (child), Sym * child) printf ("[find_cycle] tail "); print_name (tail); printf ("\n")); - } /* for */ + } /* * If what we think is the top of the cycle has a cyclehead * field, then it's not really the head of the cycle, which is @@ -149,10 +168,10 @@ DEFUN (find_cycle, (child), Sym * child) DBG (DFNDEBUG, printf ("[find_cycle] new cyclehead "); print_name (head); printf ("\n")); - } /* if */ - for (index = cycle_top + 1; index <= dfn_depth; ++index) + } + for (cycle_index = cycle_top + 1; cycle_index <= dfn_depth; ++cycle_index) { - child = dfn_stack[index].sym; + child = dfn_stack[cycle_index].sym; if (child->cg.cyc.head == child) { /* @@ -174,16 +193,16 @@ DEFUN (find_cycle, (child), Sym * child) printf (" onto "); print_name (head); printf ("\n")); - } /* for */ + } } else if (child->cg.cyc.head != head /* firewall */ ) { fprintf (stderr, "[find_cycle] glommed, but not to head\n"); done (1); - } /* if */ - } /* for */ - } /* if */ -} /* find_cycle */ + } + } + } +} /* @@ -191,21 +210,24 @@ DEFUN (find_cycle, (child), Sym * child) * the stack and mark it busy. */ static void -DEFUN (pre_visit, (parent), Sym * parent) +pre_visit (Sym *parent) { ++dfn_depth; - if (dfn_depth >= DFN_DEPTH) + + if (dfn_depth >= dfn_maxdepth) { - fprintf (stderr, "[pre_visit] dfn_stack overflow\n"); - done (1); - } /* if */ + dfn_maxdepth += DFN_INCR_DEPTH; + dfn_stack = (DFN_Stack *) xrealloc (dfn_stack, + dfn_maxdepth * sizeof *dfn_stack); + } + dfn_stack[dfn_depth].sym = parent; dfn_stack[dfn_depth].cycle_top = dfn_depth; parent->cg.top_order = DFN_BUSY; DBG (DFNDEBUG, printf ("[pre_visit]\t\t%d:", dfn_depth); print_name (parent); printf ("\n")); -} /* pre_visit */ +} /* @@ -213,7 +235,7 @@ DEFUN (pre_visit, (parent), Sym * parent) * and number functions if PARENT is head of a cycle. */ static void -DEFUN (post_visit, (parent), Sym * parent) +post_visit (Sym *parent) { Sym *member; @@ -233,21 +255,21 @@ DEFUN (post_visit, (parent), Sym * parent) DBG (DFNDEBUG, printf ("[post_visit]\t\tmember "); print_name (member); printf ("-> cg.top_order = %d\n", dfn_counter)); - } /* for */ + } } else { DBG (DFNDEBUG, printf ("[post_visit]\t\tis part of a cycle\n")); - } /* if */ + } --dfn_depth; -} /* post_visit */ +} /* * Given this PARENT, depth first number its children. */ void -DEFUN (cg_dfn, (parent), Sym * parent) +cg_dfn (Sym *parent) { Arc *arc; @@ -260,7 +282,7 @@ DEFUN (cg_dfn, (parent), Sym * parent) if (is_numbered (parent)) { return; - } /* if */ + } /* * If we're already busy, must be a cycle: */ @@ -268,7 +290,7 @@ DEFUN (cg_dfn, (parent), Sym * parent) { find_cycle (parent); return; - } /* if */ + } pre_visit (parent); /* * Recursively visit children: @@ -276,8 +298,6 @@ DEFUN (cg_dfn, (parent), Sym * parent) for (arc = parent->cg.children; arc; arc = arc->next_child) { cg_dfn (arc->child); - } /* for */ + } post_visit (parent); -} /* cg_dfn */ - -/*** end of cg_dfn.c ***/ +}