Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

prof.c File Reference

#include "c.h"

Include dependency graph for prof.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  callsite
union  callsite::coordinate
struct  func
struct  map

Functions

void bbcall (Symbol yycounts, Coordinate *cp, Tree *e)
void bbentry (Symbol yylink, Symbol f)
void bbexit (Symbol yylink, Symbol f, Tree e)
int bbfile (char *file)
void bbfunc (Symbol yylink, Symbol f)
void bbincr (Symbol yycounts, Coordinate *cp, Tree *e)
void bbvars (Symbol yylink)
void prof_init (int argc, char *argv[])

Variables

Symbol afunc
List filelist
Symbol funclist
List maplist
int ncalled = -1
int npoints
Symbol YYcounts
Symbol YYlink


Function Documentation

void bbcall Symbol  yycounts,
Coordinate cp,
Tree e
[static]
 

Definition at line 33 of file prof.c.

References array(), asgn(), assert, symbol::c, CALL, cfunc, Coordinate, cp, interface::defconst, defglobal(), symbol::defined, defpointer(), e, EXTERN, coord::file, generic, genident(), GLOBAL, idtree(), IR, tree::kids, LIT, interface::little_endian, symbol::loc, mkstr(), mksymbol(), symbol::name, tree::op, p, ptr(), RIGHT, type::size, Symbol, t, tree(), Tree, tree::type, value::u, symbol::u, unsignedtype, v, Value, voidptype, coord::x, and coord::y.

Referenced by prof_init().

00033                                                              {
00034     static Symbol caller;
00035     Value v;
00036     union coordinate u;
00037     Symbol p = genident(STATIC, array(voidptype, 0, 0), GLOBAL);
00038     Tree t = *e;
00039 
00040     defglobal(p, LIT);
00041     defpointer(cp->file ? mkstr(cp->file)->u.c.loc : (Symbol)0);
00042     defpointer(mkstr(cfunc->name)->u.c.loc);
00043     if (IR->little_endian) {
00044         u.le.x = cp->x;
00045         u.le.y = cp->y;
00046     } else {
00047         u.be.x = cp->x;
00048         u.be.y = cp->y;
00049     }
00050     (*IR->defconst)(U, unsignedtype->size, (v.u = u.coord, v));
00051     if (caller == 0) {
00052         caller = mksymbol(EXTERN, "_caller", ptr(voidptype));
00053         caller->defined = 0;
00054     }
00055     if (generic((*e)->op) != CALL)
00056         t = (*e)->kids[0];
00057     assert(generic(t->op) == CALL);
00058     t = tree(t->op, t->type,
00059         tree(RIGHT, t->kids[0]->type,
00060             t->kids[0],
00061             tree(RIGHT, t->kids[0]->type, asgn(caller, idtree(p)), t->kids[0])),
00062         t->kids[1]);
00063     if (generic((*e)->op) != CALL)
00064         t = tree((*e)->op, (*e)->type, t, (*e)->kids[1]);
00065     *e = t;
00066 }

Here is the call graph for this function:

void bbentry Symbol  yylink,
Symbol  f
[static]
 

Definition at line 69 of file prof.c.

References afunc, array(), symbol::defined, EXTERN, ftype(), genident(), GLOBAL, idtree(), inttype, mksymbol(), NULL, pointer(), Symbol, vcall(), voidptype, voidtype, and walk().

Referenced by prof_init().

00069                                              {
00070     static Symbol prologue;
00071     
00072     afunc = genident(STATIC, array(voidptype, 4, 0), GLOBAL);
00073     if (prologue == 0) {
00074         prologue = mksymbol(EXTERN, "_prologue", ftype(inttype, voidptype));
00075         prologue->defined = 0;
00076     }
00077     walk(vcall(prologue, voidtype, pointer(idtree(afunc)), pointer(idtree(yylink)), NULL), 0, 0);
00078 
00079 }

Here is the call graph for this function:

void bbexit Symbol  yylink,
Symbol  f,
Tree  e
[static]
 

Definition at line 82 of file prof.c.

References afunc, symbol::defined, EXTERN, ftype(), idtree(), inttype, mksymbol(), NULL, pointer(), Symbol, Tree, vcall(), voidptype, voidtype, and walk().

Referenced by prof_init().

00082                                                     {
00083     static Symbol epilogue;
00084     
00085     if (epilogue == 0) {
00086         epilogue = mksymbol(EXTERN, "_epilogue", ftype(inttype, voidptype));
00087         epilogue->defined = 0;
00088     }
00089     walk(vcall(epilogue, voidtype, pointer(idtree(afunc)), NULL), 0, 0);
00090 }

Here is the call graph for this function:

int bbfile char *  file  )  [static]
 

Definition at line 93 of file prof.c.

References append(), file, filelist, i, list::link, List, mkstr(), Symbol, and list::x.

Referenced by bbfunc(), and bbincr().

00093                               {
00094     if (file) {
00095         List lp;
00096         int i = 1;
00097         if ((lp = filelist) != NULL)
00098             do {
00099                 lp = lp->link;
00100                 if (((Symbol)lp->x)->u.c.v.p == file)
00101                     return i;
00102                 i++;
00103             } while (lp != filelist);
00104         filelist = append(mkstr(file), filelist);
00105         return i;
00106     }
00107     return 0;
00108 }

Here is the call graph for this function:

void bbfunc Symbol  yylink,
Symbol  f
[static]
 

Definition at line 111 of file prof.c.

References afunc, bbfile(), symbol::c, DATA, interface::defconst, defglobal(), defpointer(), symbol::f, f, coord::file, funclist, IR, interface::little_endian, symbol::loc, mkstr(), symbol::name, NULL, symbol::pt, type::size, Symbol, value::u, symbol::u, unsignedtype, v, Value, coord::x, list::x, and coord::y.

Referenced by prof_init().

00111                                             {
00112     Value v;
00113     union coordinate u;
00114 
00115     defglobal(afunc, DATA);
00116     defpointer(funclist);
00117     defpointer(NULL);
00118     defpointer(mkstr(f->name)->u.c.loc);
00119     if (IR->little_endian) {
00120         u.le.x = f->u.f.pt.x;
00121         u.le.y = f->u.f.pt.y;
00122         u.le.index = bbfile(f->u.f.pt.file);
00123     } else {
00124         u.be.x = f->u.f.pt.x;
00125         u.be.y = f->u.f.pt.y;
00126         u.be.index = bbfile(f->u.f.pt.file);
00127     }
00128     (*IR->defconst)(U, unsignedtype->size, (v.u = u.coord, v));
00129     funclist = afunc;
00130 }

Here is the call graph for this function:

void bbincr Symbol  yycounts,
Coordinate cp,
Tree e
[static]
 

Definition at line 133 of file prof.c.

References ADD, append(), bbfile(), consttree(), Coordinate, cp, e, coord::file, idtree(), incr(), inttype, IR, interface::little_endian, maplist, NELEMS, NEW, npoints, optree, PERM, pointer(), RIGHT, rvalue(), map::size, Symbol, t, tree(), Tree, map::u, coord::x, list::x, and coord::y.

Referenced by prof_init().

00133                                                              {
00134     struct map *mp = maplist->x;
00135     Tree t;
00136 
00137     /* append *cp to source map */
00138     if (mp->size >= NELEMS(mp->u)) {
00139         NEW(mp, PERM);
00140         mp->size = 0;
00141         maplist = append(mp, maplist);
00142     }
00143     if (IR->little_endian) {
00144         mp->u[mp->size].le.x = cp->x;
00145         mp->u[mp->size].le.y = cp->y;
00146         mp->u[mp->size++].le.index = bbfile(cp->file);
00147     } else {
00148         mp->u[mp->size].be.x = cp->x;
00149         mp->u[mp->size].be.y = cp->y;
00150         mp->u[mp->size++].be.index = bbfile(cp->file);
00151     }
00152     t = incr('+', rvalue((*optree['+'])(ADD, pointer(idtree(yycounts)),
00153         consttree(npoints++, inttype))), consttree(1, inttype));
00154     if (*e)
00155         *e = tree(RIGHT, (*e)->type, t, *e);
00156     else
00157         *e = t;
00158 }

Here is the call graph for this function:

void bbvars Symbol  yylink  )  [static]
 

Definition at line 161 of file prof.c.

References array(), BSS, charptype, DATA, interface::defconst, defglobal(), defpointer(), filelist, funclist, genident(), GLOBAL, i, IR, j, LIT, ltov(), maplist, n, NULL, p, PERM, type::size, interface::space, Symbol, type::type, symbol::type, value::u, unsignedtype, v, Value, and YYcounts.

Referenced by prof_init().

00161                                   {
00162     int i, j, n = npoints;
00163     Value v;
00164     struct map **mp;
00165     Symbol coords, files, *p;
00166 
00167     if (!YYcounts && !yylink)
00168         return;
00169     if (YYcounts) {
00170         if (n <= 0)
00171             n = 1;
00172         YYcounts->type = array(unsignedtype, n, 0);
00173         defglobal(YYcounts, BSS);
00174     }
00175     files = genident(STATIC, array(charptype, 1, 0), GLOBAL);
00176     defglobal(files, LIT);
00177     for (p = ltov(&filelist, PERM); *p; p++)
00178         defpointer((*p)->u.c.loc);
00179     defpointer(NULL);
00180     coords = genident(STATIC, array(unsignedtype, n, 0), GLOBAL);
00181     defglobal(coords, LIT);
00182     for (i = n, mp = ltov(&maplist, PERM); *mp; i -= (*mp)->size, mp++)
00183         for (j = 0; j < (*mp)->size; j++)
00184             (*IR->defconst)(U, unsignedtype->size, (v.u = (*mp)->u[j].coord, v));
00185     if (i > 0)
00186         (*IR->space)(i*coords->type->type->size);
00187     defpointer(NULL);
00188     defglobal(yylink, DATA);
00189     defpointer(NULL);
00190     (*IR->defconst)(U, unsignedtype->size, (v.u = n, v));
00191     defpointer(YYcounts);
00192     defpointer(coords);
00193     defpointer(files);
00194     defpointer(funclist);
00195 }

Here is the call graph for this function:

void prof_init int  argc,
char *  argv[]
 

Definition at line 198 of file prof.c.

References allocate(), append(), Apply, argc, argv, array(), attach(), bbcall(), bbentry(), bbexit(), bbfunc(), bbincr(), bbvars(), Events::calls, Events::end, Events::entry, events, Events::exit, genident(), GLOBAL, i, maplist, ncalled, PERM, Events::points, process(), Events::returns, strcmp(), strncmp(), type_init(), unsignedtype, list::x, YYcounts, and YYlink.

Referenced by init().

00198                                        {
00199     int i;
00200     static int inited;
00201 
00202     if (inited)
00203         return;
00204     inited = 1;
00205     type_init(argc, argv);
00206     if (IR)
00207         for (i = 1; i < argc; i++)
00208             if (strncmp(argv[i], "-a", 2) == 0) {
00209                 if (ncalled == -1
00210                 && process(argv[i][2] ? &argv[i][2] : "prof.out") > 0)
00211                     ncalled = 0;
00212             } else if ((strcmp(argv[i], "-b") == 0
00213                      || strcmp(argv[i], "-C") == 0) && YYlink == 0) {
00214                 YYlink = genident(STATIC, array(unsignedtype, 0, 0), GLOBAL);
00215                 attach((Apply)bbentry, YYlink, &events.entry);
00216                 attach((Apply)bbexit,  YYlink, &events.returns);
00217                 attach((Apply)bbfunc,  YYlink, &events.exit);
00218                 attach((Apply)bbvars,  YYlink, &events.end);
00219                 if (strcmp(argv[i], "-b") == 0) {
00220                     YYcounts = genident(STATIC, array(unsignedtype, 0, 0), GLOBAL);
00221                     maplist = append(allocate(sizeof (struct map), PERM), maplist);
00222                     ((struct map *)maplist->x)->size = 0;
00223                     attach((Apply)bbcall, YYcounts, &events.calls);
00224                     attach((Apply)bbincr, YYcounts, &events.points);
00225                 }
00226             }
00227 }

Here is the call graph for this function:


Variable Documentation

Symbol afunc [static]
 

Definition at line 30 of file prof.c.

Referenced by bbentry(), bbexit(), and bbfunc().

List filelist [static]
 

Definition at line 28 of file prof.c.

Symbol funclist [static]
 

Definition at line 29 of file prof.c.

Referenced by bbfunc(), and bbvars().

List maplist [static]
 

Definition at line 27 of file prof.c.

Referenced by bbincr(), bbvars(), and prof_init().

int ncalled = -1
 

Definition at line 24 of file prof.c.

Referenced by definept(), funcdefn(), and prof_init().

int npoints
 

Definition at line 23 of file prof.c.

Referenced by bbincr(), and gather().

Symbol YYcounts [static]
 

Definition at line 26 of file prof.c.

Referenced by bbvars(), and prof_init().

Symbol YYlink [static]
 

Definition at line 25 of file prof.c.

Referenced by prof_init().


Generated on Thu Aug 25 15:55:20 2005 for Quake III Arena by  doxygen 1.3.9.1