#include #include #include #include long long psu_clock = 0; struct _write { unsigned int addr; long long psu_time; struct _write *hash_next; }; #define WRITE_HMASK ((1<<16) - 1) #define WRITE_HTAB_SIZE (WRITE_HMASK + 1) struct _write *w_htab[WRITE_HTAB_SIZE]; int w_hfunc (unsigned int addr) { return (addr>>4) & WRITE_HMASK; } static lookup_write (unsigned int addr) { int h; struct _write *w; h = w_hfunc (addr); w = w_htab[h]; while (w && (w->addr < addr)) w = w->hash_next; if (w && (w->addr == addr)) return w->psu_time; else return 0; } static struct _write ** search_write (unsigned int addr) { int h; struct _write **_w; h = w_hfunc (addr); _w = &w_htab[h]; while (*_w && ((*_w)->addr < addr)) _w = &(*_w)->hash_next; return _w; } static void update_write (unsigned int addr) { struct _write **_w; struct _write *new_write; _w = search_write (addr); if (*_w && (*_w)->addr == addr) { (*_w)->psu_time = psu_clock; } else { new_write = calloc (1, sizeof(struct _write)); new_write->addr = addr; new_write->psu_time = psu_clock; new_write->hash_next = *_w; *_w = new_write; } } #define LOCAL_VAR_HASH_SIZE 68111 static long long m_LocalVarHash[LOCAL_VAR_HASH_SIZE]; static void update_local_write (int var) { m_LocalVarHash[var] = psu_clock; } static long long lookup_local_write (int var) { return m_LocalVarHash[var]; } typedef struct { int src; int dest; } dependence_t; typedef struct { int rid; dependence_t *dependences; } region_data_t; typedef struct { char *name; struct function_data_s **functions; } file_data_t; typedef struct function_data_s { file_data_t *file; char *name; region_data_t *region_data; struct function_data_s *next; struct function_data_s *hash_next; } *function_data_t; #define MAX_FILE_NUM 100 typedef struct { int type; union { function_data_t func; int region_id; } u; int parent_id; int pos_in_parent_region; int size; long long *stamps; } stack_frame_t; #define FRAME_FUNCTION 0 #define FRAME_REGION 1 #define MAX_STACK_DEPTH 1000 stack_frame_t trace_stack[MAX_STACK_DEPTH]; int stack_top = -1; function_data_t current_function; region_data_t *current_region; long long *current_stamp; void _bop_prof_init () { memset ((void *)w_htab, 0, WRITE_HTAB_SIZE * sizeof (void *)); memset ((void *)m_LocalVarHash, 0, LOCAL_VAR_HASH_SIZE * sizeof (long long)); } void _bop_prof_fini () { } void bop_instm_rgn_entry (int region_id, int parent_id, int nstamps, int pos_in_parent) { } void bop_instm_rgn_exit () { } void bop_instm_func_entry (const char *file_name, const char *func_name, int nregions) { } void bop_instm_func_exit () { } void _bop_prof_update_time (int pos) { psu_clock++; } void _bop_prof_rec_read (unsigned int addr) { long long wstamp; wstamp = lookup_write (addr); if (!wstamp) return; fprintf (stderr, "%lld %lld\n", wstamp, psu_clock); } void _bop_prof_rec_local_read (int var) { long long wstamp; wstamp = lookup_local_write (var); if (!wstamp) return; fprintf (stderr, "%lld %lld\n", wstamp, psu_clock); } void _bop_prof_rec_write (unsigned int addr) { update_write (addr); } void _bop_prof_rec_local_write (int var) { update_local_write (var); }