version 1.1, 2001/02/27 21:17:11
|
version 1.8, 2003/03/09 15:17:03
|
Line 1
|
Line 1
|
/* VM profiling support stuff |
/* VM profiling support stuff |
|
|
Copyright (C) 2001 Free Software Foundation, Inc. |
Copyright (C) 2001,2002 Free Software Foundation, Inc. |
|
|
This file is part of Gforth. |
This file is part of Gforth. |
|
|
Line 20
|
Line 20
|
*/ |
*/ |
|
|
#include "config.h" |
#include "config.h" |
|
#include "forth.h" |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |
#include "forth.h" |
#include <assert.h> |
|
|
|
|
/* data structure: simple hash table with external chaining */ |
/* data structure: simple hash table with external chaining */ |
|
|
Line 65 block_count *block_insert(Xt *ip)
|
Line 67 block_count *block_insert(Xt *ip)
|
new->ip = ip; |
new->ip = ip; |
new->count = 0LL; |
new->count = 0LL; |
new->insts = malloc(0); |
new->insts = malloc(0); |
|
assert(new->insts != NULL); |
new->ninsts = 0; |
new->ninsts = 0; |
blocks[hash(ip)] = new; |
blocks[hash(ip)] = new; |
return new; |
return new; |
Line 72 block_count *block_insert(Xt *ip)
|
Line 75 block_count *block_insert(Xt *ip)
|
|
|
void add_inst(block_count *b, char *inst) |
void add_inst(block_count *b, char *inst) |
{ |
{ |
b->insts = realloc(b->insts, b->ninsts * sizeof(char *)); |
b->insts = realloc(b->insts, (b->ninsts+1) * sizeof(char *)); |
b->insts[b->ninsts++] = inst; |
b->insts[b->ninsts++] = inst; |
} |
} |
|
|
Line 81 void vm_count_block(Xt *ip)
|
Line 84 void vm_count_block(Xt *ip)
|
block_insert(ip)->count++; |
block_insert(ip)->count++; |
} |
} |
|
|
/* !! fix this */ |
#ifdef DIRECT_THREADED |
#define VM_INST(n) NULL |
#define VM_IS_INST(inst, n) ((inst) == vm_prims[(n)+DOESJUMP+1]) |
|
#else |
|
#define VM_IS_INST(inst, n) ((inst) == &(vm_prims[(n)+DOESJUMP+1])) |
|
#endif |
|
|
void postprocess_block(block_count *b) |
void postprocess_block(block_count *b) |
{ |
{ |
Line 96 void postprocess_block(block_count *b)
|
Line 102 void postprocess_block(block_count *b)
|
add_inst(b,"unknown"); |
add_inst(b,"unknown"); |
ip++; |
ip++; |
} |
} |
|
_endif_: |
next_block = block_lookup(ip); |
next_block = block_lookup(ip); |
} while (next_block == NULL); |
} while (next_block == NULL); |
/* we fell through, so set fallthrough and update the count */ |
/* we fell through, so set fallthrough and update the count */ |
Line 121 void postprocess(void)
|
Line 128 void postprocess(void)
|
} |
} |
} |
} |
|
|
|
#if 0 |
|
/* full basic blocks only */ |
|
void print_block(FILE *file, block_count *b) |
|
{ |
|
size_t i; |
|
|
|
fprintf(file,"%14lld\t",b->count); |
|
for (i=0; i<b->ninsts; i++) |
|
fprintf(file, "%s ", b->insts[i]); |
|
putc('\n', file); |
|
} |
|
#elif 0 |
|
/* full basic blocks and all their prefixes */ |
void print_block(FILE *file, block_count *b) |
void print_block(FILE *file, block_count *b) |
{ |
{ |
fprintf(file,"%12lld ip=%p\n",b->count,b->ip); |
size_t i,j; |
|
|
|
for (j=1; j<=b->ninsts; j++) { |
|
fprintf(file,"%14lld\t",b->count); |
|
for (i=0; i<j; i++) |
|
fprintf(file, "%s ", b->insts[i]); |
|
putc('\n', file); |
|
} |
|
} |
|
#else |
|
/* all subsequences up to length 12 */ |
|
void print_block(FILE *file, block_count *b) |
|
{ |
|
size_t i,j,k; |
|
|
|
for (i=2; i<12; i++) |
|
for (j=0; i+j<=b->ninsts; j++) { |
|
fprintf(file,"%14lld\t",b->count); |
|
for (k=j; k<i+j; k++) |
|
fprintf(file, "%s ", b->insts[k]); |
|
putc('\n', file); |
|
} |
} |
} |
|
#endif |
|
|
void vm_print_profile(FILE *file) |
void vm_print_profile(FILE *file) |
{ |
{ |