1 /* Copyright (c) 2015 Regents of the University of California
3 * Author: Brian Demsky <bdemsky@uci.edu>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
10 #include "execpoint.h"
17 ExecPoint::ExecPoint(int _length, thread_id_t thread_id) :
20 pairarray((execcount_t *)model_malloc(sizeof(execcount_t)*length)),
21 hashvalue(id_to_int(thread_id)),
26 ExecPoint::ExecPoint(ExecPoint *e) :
29 pairarray((execcount_t *)model_malloc(sizeof(execcount_t)*length)),
30 hashvalue(e->hashvalue),
33 memcpy(pairarray, e->pairarray, sizeof(execcount_t)*length);
36 ExecPoint::~ExecPoint() {
37 model_free(pairarray);
40 void ExecPoint::reset() {
42 hashvalue=id_to_int(tid);
45 /** Return CR_AFTER means that ep occurs after this.
46 Return CR_BEFORE means tha te occurs before this.
47 Return CR_EQUALS means that they are the same point.
48 Return CR_INCOMPARABLE means that they are not comparable.
51 CompareResult ExecPoint::compare(const ExecPoint * ep) const {
54 unsigned int minsize=(size<ep->size)?size:ep->size;
55 for(unsigned int i=0;i<minsize;i+=2) {
56 ASSERT(pairarray[i]==ep->pairarray[i]);
57 if (pairarray[i+1]!=ep->pairarray[i+1]) {
58 //we have a difference
59 if (pairarray[i]==EP_BRANCH)
60 return CR_INCOMPARABLE;
61 else if (pairarray[i+1]<ep->pairarray[i+1])
69 else if (size > ep->size)
75 void ExecPoint::pop() {
76 hashvalue = rotate_right((hashvalue ^ pairarray[size-1]), 3);
80 bool ExecPoint::directInLoop() {
81 return ((ExecPointType)pairarray[size-4])==EP_LOOP;
84 bool ExecPoint::inLoop() {
86 for(index=size-2;index>0;index-=2) {
87 if ((ExecPointType)pairarray[index]==EP_LOOP)
93 ExecPointType ExecPoint::getType() {
94 return (ExecPointType)pairarray[size-2];
97 void ExecPoint::push(ExecPointType type, execcount_t value) {
100 execcount_t *tmp=(execcount_t *)model_malloc(sizeof(execcount_t)*length);
101 memcpy(tmp, pairarray, sizeof(execcount_t)*size);
102 model_free(pairarray);
105 hashvalue = rotate_left(hashvalue, 3) ^ value;
106 pairarray[size++]=type;
107 pairarray[size++]=value;
110 void ExecPoint::incrementTop() {
111 execcount_t current=pairarray[size-1];
112 hashvalue = hashvalue ^ current ^ (current+1);
113 pairarray[size-1]=current+1;
116 unsigned int ExecPointHash(ExecPoint *e) {
120 bool ExecPointEquals(ExecPoint *e1, ExecPoint * e2) {
123 if (e1->tid != e2->tid || e1->size != e2->size || e1->hashvalue != e2->hashvalue)
125 for(unsigned int i=0; i<e1->size; i++) {
126 if (e1->pairarray[i]!=e2->pairarray[i])
132 void ExecPoint::print(int f) {
133 model_dprintf(f,"<tid=%u,",tid);
134 for(unsigned int i=0;i<size;i+=2) {
135 switch((ExecPointType)pairarray[i]) {
137 model_dprintf(f,"br");
140 model_dprintf(f,"cnt");
143 model_dprintf(f,"lp");
148 model_dprintf(f, "(%u)", pairarray[i+1]);
150 model_dprintf(f, ", ");
152 model_dprintf(f, ">");
155 void ExecPoint::print() {
156 model_print("<tid=%u,",tid);
157 for(unsigned int i=0;i<size;i+=2) {
158 switch((ExecPointType)pairarray[i]) {
171 model_print("(%u)", pairarray[i+1]);