Back to index

cell-binutils  2.17cvs20070401
Classes | Typedefs | Functions | Variables
cg_arcs.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  arc

Typedefs

typedef struct arc Arc

Functions

void arc_add (Sym *parent, Sym *child, unsigned long count)
Arcarc_lookup (Sym *parent, Sym *child)
Sym ** cg_assemble (void)

Variables

unsigned int num_cycles
Symcycle_header
Arc ** arcs
unsigned int numarcs

Class Documentation

struct arc

Definition at line 11 of file cg_arcs.h.

Collaboration diagram for arc:
Class Members
Sym * child
double child_time
unsigned long count
int has_been_placed
struct arc * next_child
struct arc * next_parent
Sym * parent
double time

Typedef Documentation

typedef struct arc Arc

Function Documentation

void arc_add ( Sym parent,
Sym child,
unsigned long  count 
)

Definition at line 88 of file cg_arcs.c.

{
  static unsigned int maxarcs = 0;
  Arc *arc, **newarcs;

  DBG (TALLYDEBUG, printf ("[arc_add] %lu arcs from %s to %s\n",
                        count, parent->name, child->name));
  arc = arc_lookup (parent, child);
  if (arc)
    {
      /*
       * A hit: just increment the count.
       */
      DBG (TALLYDEBUG, printf ("[tally] hit %lu += %lu\n",
                            arc->count, count));
      arc->count += count;
      return;
    }
  arc = (Arc *) xmalloc (sizeof (*arc));
  memset (arc, 0, sizeof (*arc));
  arc->parent = parent;
  arc->child = child;
  arc->count = count;

  /* If this isn't an arc for a recursive call to parent, then add it
     to the array of arcs.  */
  if (parent != child)
    {
      /* If we've exhausted space in our current array, get a new one
        and copy the contents.   We might want to throttle the doubling
        factor one day.  */
      if (numarcs == maxarcs)
       {
         /* Determine how much space we want to allocate.  */
         if (maxarcs == 0)
           maxarcs = 1;
         maxarcs *= 2;

         /* Allocate the new array.  */
         newarcs = (Arc **)xmalloc(sizeof (Arc *) * maxarcs);

         /* Copy the old array's contents into the new array.  */
         memcpy (newarcs, arcs, numarcs * sizeof (Arc *));

         /* Free up the old array.  */
         free (arcs);

         /* And make the new array be the current array.  */
         arcs = newarcs;
       }

      /* Place this arc in the arc array.  */
      arcs[numarcs++] = arc;
    }

  /* prepend this child to the children of this parent: */
  arc->next_child = parent->cg.children;
  parent->cg.children = arc;

  /* prepend this parent to the parents of this child: */
  arc->next_parent = child->cg.parents;
  child->cg.parents = arc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Arc* arc_lookup ( Sym parent,
Sym child 
)

Definition at line 59 of file cg_arcs.c.

{
  Arc *arc;

  if (!parent || !child)
    {
      printf ("[arc_lookup] parent == 0 || child == 0\n");
      return 0;
    }
  DBG (LOOKUPDEBUG, printf ("[arc_lookup] parent %s child %s\n",
                         parent->name, child->name));
  for (arc = parent->cg.children; arc; arc = arc->next_child)
    {
      DBG (LOOKUPDEBUG, printf ("[arc_lookup]\t parent %s child %s\n",
                            arc->parent->name, arc->child->name));
      if (child->addr >= arc->child->addr
         && child->end_addr <= arc->child->end_addr)
       {
         return arc;
       }
    }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Sym** cg_assemble ( void  )

Definition at line 595 of file cg_arcs.c.

{
  Sym *parent, **time_sorted_syms, **top_sorted_syms;
  unsigned int index;
  Arc *arc;

  /*
   * initialize various things:
   *      zero out child times.
   *      count self-recursive calls.
   *      indicate that nothing is on cycles.
   */
  for (parent = symtab.base; parent < symtab.limit; parent++)
    {
      parent->cg.child_time = 0.0;
      arc = arc_lookup (parent, parent);
      if (arc && parent == arc->child)
       {
         parent->ncalls -= arc->count;
         parent->cg.self_calls = arc->count;
       }
      else
       {
         parent->cg.self_calls = 0;
       }
      parent->cg.prop.fract = 0.0;
      parent->cg.prop.self = 0.0;
      parent->cg.prop.child = 0.0;
      parent->cg.print_flag = FALSE;
      parent->cg.top_order = DFN_NAN;
      parent->cg.cyc.num = 0;
      parent->cg.cyc.head = parent;
      parent->cg.cyc.next = 0;
      if (ignore_direct_calls)
       {
         find_call (parent, parent->addr, (parent + 1)->addr);
       }
    }
  /*
   * Topologically order things.  If any node is unnumbered, number
   * it and any of its descendents.
   */
  for (parent = symtab.base; parent < symtab.limit; parent++)
    {
      if (parent->cg.top_order == DFN_NAN)
       {
         cg_dfn (parent);
       }
    }

  /* link together nodes on the same cycle: */
  cycle_link ();

  /* sort the symbol table in reverse topological order: */
  top_sorted_syms = (Sym **) xmalloc (symtab.len * sizeof (Sym *));
  for (index = 0; index < symtab.len; ++index)
    {
      top_sorted_syms[index] = &symtab.base[index];
    }
  qsort (top_sorted_syms, symtab.len, sizeof (Sym *), cmp_topo);
  DBG (DFNDEBUG,
       printf ("[cg_assemble] topological sort listing\n");
       for (index = 0; index < symtab.len; ++index)
       {
       printf ("[cg_assemble] ");
       printf ("%d:", top_sorted_syms[index]->cg.top_order);
       print_name (top_sorted_syms[index]);
       printf ("\n");
       }
  );
  /*
   * Starting from the topological top, propagate print flags to
   * children.  also, calculate propagation fractions.  this happens
   * before time propagation since time propagation uses the
   * fractions.
   */
  propagate_flags (top_sorted_syms);

  /*
   * Starting from the topological bottom, propogate children times
   * up to parents.
   */
  cycle_time ();
  for (index = 0; index < symtab.len; ++index)
    {
      propagate_time (top_sorted_syms[index]);
    }

  free (top_sorted_syms);

  /*
   * Now, sort by CG.PROP.SELF + CG.PROP.CHILD.  Sorting both the regular
   * function names and cycle headers.
   */
  time_sorted_syms = (Sym **) xmalloc ((symtab.len + num_cycles) * sizeof (Sym *));
  for (index = 0; index < symtab.len; index++)
    {
      time_sorted_syms[index] = &symtab.base[index];
    }
  for (index = 1; index <= num_cycles; index++)
    {
      time_sorted_syms[symtab.len + index - 1] = &cycle_header[index];
    }
  qsort (time_sorted_syms, symtab.len + num_cycles, sizeof (Sym *),
        cmp_total);
  for (index = 0; index < symtab.len + num_cycles; index++)
    {
      time_sorted_syms[index]->cg.index = index + 1;
    }
  return time_sorted_syms;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Arc** arcs

Definition at line 51 of file cg_arcs.c.

Definition at line 49 of file cg_arcs.c.

Definition at line 50 of file cg_arcs.c.

Definition at line 52 of file cg_arcs.c.