Skip to content

Commit

Permalink
simulate hse fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanohar committed Feb 4, 2023
1 parent 1be0040 commit 6d8c458
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 13 deletions.
12 changes: 4 additions & 8 deletions actsim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,14 @@ ChpSim *ActSimCore::_add_chp (act_chp *c)
b->v = pgi;
}
if (!pgi->chp) {
ChpSimGraph *stop;
NEW (pgi->chp, chpsimgraph_info);
if (c->c && c->c->type == ACT_CHP_COMMA) {
setInternalParallel (1);
}
else {
setInternalParallel (0);
}
pgi->chp->g = ChpSimGraph::buildChpSimGraph (this, c->c, &stop);
pgi->chp->g = ChpSimGraph::buildChpSimGraph (this, c->c);
pgi->chp->e = NULL;
pgi->chp->max_count = ChpSimGraph::max_pending_count;
pgi->chp->max_stats = ChpSimGraph::max_stats;
Expand Down Expand Up @@ -413,7 +412,6 @@ ChpSim *ActSimCore::_add_hse (act_chp *c)
}

if (!pgi->hse) {
ChpSimGraph *stop;
NEW (pgi->hse, chpsimgraph_info);

if (c->c && c->c->type == ACT_CHP_COMMA) {
Expand All @@ -422,7 +420,7 @@ ChpSim *ActSimCore::_add_hse (act_chp *c)
else {
setInternalParallel (0);
}
pgi->hse->g = ChpSimGraph::buildChpSimGraph (this, c->c, &stop);
pgi->hse->g = ChpSimGraph::buildChpSimGraph (this, c->c);
pgi->hse->max_count = ChpSimGraph::max_pending_count;
pgi->hse->max_stats = ChpSimGraph::max_stats;
}
Expand Down Expand Up @@ -2030,8 +2028,7 @@ void ActSim::runInit ()
for (int i=0; i < num; i++) {
if (lia[i] && list_next (lia[i])) {
act_chp_lang_t *c = (act_chp_lang_t *) list_value (lia[i]);
ChpSimGraph *stop;
ChpSimGraph *sg = ChpSimGraph::buildChpSimGraph (this, c, &stop);
ChpSimGraph *sg = ChpSimGraph::buildChpSimGraph (this, c);
ChpSim *sim_init =
new ChpSim (sg, ChpSimGraph::max_pending_count, 0, c, this, NULL);

Expand Down Expand Up @@ -2061,8 +2058,7 @@ void ActSim::runInit ()
for (int i=0; i < num; i++) {
if (lia[i]) {
act_chp_lang_t *c = (act_chp_lang_t *) list_value (lia[i]);
ChpSimGraph *stop;
ChpSimGraph *sg = ChpSimGraph::buildChpSimGraph (this, c, &stop);
ChpSimGraph *sg = ChpSimGraph::buildChpSimGraph (this, c);
ChpSim *sim_init =
new ChpSim (sg, ChpSimGraph::max_pending_count, 0, c, this, NULL);

Expand Down
148 changes: 145 additions & 3 deletions chpsim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,10 @@ int ChpSim::Step (Event *ev)
int choice = -1;
BigInt res;

if (stmt->type == CHPSIM_COND || stmt->type == CHPSIM_CONDARB) {
printf ("cond");
}

#ifdef DUMP_ALL
if (stmt->type == CHPSIM_COND || stmt->type == CHPSIM_CONDARB) {
printf ("cond");
Expand Down Expand Up @@ -3135,6 +3139,17 @@ int ChpSim::_max_program_counters (act_chp_lang_t *c)
if (!c) return 1;

switch (c->type) {
case ACT_HSE_FRAGMENTS:
ret = 1;
while (c) {
val = _max_program_counters (c->u.frag.body);
if (val > ret) {
ret = val;
}
c = c->u.frag.next;
}
break;

case ACT_CHP_SEMI:
ret = 1;
for (listitem_t *li = list_first (c->u.semi_comma.cmd);
Expand Down Expand Up @@ -3485,6 +3500,13 @@ void ChpSim::_compute_used_variables_helper (act_chp_lang_t *c)
if (!c) return;

switch (c->type) {
case ACT_HSE_FRAGMENTS:
while (c) {
_compute_used_variables_helper (c->u.frag.body);
c = c->u.frag.next;
}
break;

case ACT_CHP_SEMI:
case ACT_CHP_COMMA:
for (listitem_t *li = list_first (c->u.semi_comma.cmd);
Expand Down Expand Up @@ -4222,13 +4244,123 @@ static chpsimstmt *gc_to_chpsim (act_chp_gc_t *gc, ActSimCore *s)
}

ChpSimGraph *ChpSimGraph::buildChpSimGraph (ActSimCore *sc,
act_chp_lang_t *c,
ChpSimGraph **stop)
act_chp_lang_t *c)
{
ChpSimGraph *stop;
cur_pending_count = 0;
max_pending_count = 0;
max_stats = 0;
return _buildChpSimGraph (sc, c, stop);

if (c->type == ACT_HSE_FRAGMENTS) {
int len = 0;
int i;
act_chp_lang_t *ch;
ChpSimGraph **nstop;
ChpSimGraph **frags;
struct Hashtable *fH;
hash_bucket_t *b;
for (ch = c; ch; ch = ch->u.frag.next) {
len++;
}
// i = # of fragments
MALLOC (nstop, ChpSimGraph *, len);
MALLOC (frags, ChpSimGraph *, len);
fH = hash_new (4);
i = 0;
for (ch = c; ch; ch = ch->u.frag.next) {
b = hash_add (fH, ch->label);
b->i = i;
frags[i] = _buildChpSimGraph (sc, ch->u.frag.body, &nstop[i]);
i++;
}

// now wire everything up
i = 0;
for (ch = c; ch; ch = ch->u.frag.next) {
if (ch->u.frag.nextlabel) {
b = hash_lookup (fH, ch->u.frag.nextlabel);
Assert (b, "Hmm");
// now link nstop[i] to frags[b->i]
if (nstop[i]->next) {
warning ("Unused target branch for statement #%d?", i);
}
else {
nstop[i]->next = frags[b->i];
}
}
else {
ChpSimGraph *bstmt;
chpsimstmt *branch;
chpsimcond *tmp;
int flags;
int j;

// build chpsimstmt

NEW (branch, chpsimstmt);
branch->type = CHPSIM_COND;
branch->delay_cost = 0;
branch->energy_cost = 0;
branch->u.cond.stats = -1;
branch->u.cond.is_shared = 0;
branch->u.cond.is_probe = 0;

bstmt = new ChpSimGraph (sc);
MALLOC (bstmt->all, ChpSimGraph *, len);
bstmt->stmt = branch;

// dummy next: empty statement!
bstmt->next = new ChpSimGraph (sc);

// we need a guarded command now!
tmp = NULL;
flags = 0;
j = 0;
for (listitem_t *li = list_first (ch->u.frag.exit_conds); li;
li = list_next (li)) {
// first thing is an expression
Expr *e = (Expr *) list_value (li);
if (!tmp) {
tmp = &branch->u.cond.c;
}
else {
NEW (tmp->next, chpsimcond);
tmp = tmp->next;
}
tmp->next = NULL;
tmp->g = expr_to_chp_expr (e, sc, &flags);

// then label
li = list_next (li);
b = hash_lookup (fH, (char *)list_value (li));
Assert (b, "What?");
bstmt->all[j] = frags[b->i];
j++;
}
if (flags & 0x1) {
branch->u.cond.is_probe = 1;
}
if (flags & 0x2) {
branch->u.cond.is_shared = 1;
// no internal parallelism!
}
if (nstop[i]->next) {
warning ("Unused target branch for statement #%d?", i);
}
else {
nstop[i]->next = bstmt;
}
}
i++;
}
hash_free (fH);
stop = frags[0];
FREE (frags);
FREE (nstop);
return stop;
}
stop = new ChpSimGraph (sc);
return _buildChpSimGraph (sc, c, &stop);
}

static ChpSimGraph *_gen_nop (ActSimCore *sc)
Expand Down Expand Up @@ -4798,6 +4930,13 @@ void ChpSimGraph::checkFragmentation (ActSimCore *sc, ChpSim *cc,
if (!c) return;

switch (c->type) {
case ACT_HSE_FRAGMENTS:
while (c) {
checkFragmentation (sc, cc, c->u.frag.body);
c = c->u.frag.next;
}
break;

case ACT_CHP_SEMI:
case ACT_CHP_COMMA:
for (li = list_first (c->u.semi_comma.cmd); li; li = list_next (li)) {
Expand Down Expand Up @@ -4851,6 +4990,9 @@ void ChpSimGraph::recordChannel (ActSimCore *sc, ChpSim *cc,
if (!c) return;

switch (c->type) {
case ACT_HSE_FRAGMENTS:
break;

case ACT_CHP_SEMI:
case ACT_CHP_COMMA:
for (li = list_first (c->u.semi_comma.cmd); li; li = list_next (li)) {
Expand Down
3 changes: 1 addition & 2 deletions chpsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ class ChpSimGraph {
ChpSimGraph *completed (int pc, int *tot, int *done);
void printStmt (FILE *fp, Process *p);

static ChpSimGraph *buildChpSimGraph (ActSimCore *,
act_chp_lang_t *, ChpSimGraph **stop);
static ChpSimGraph *buildChpSimGraph (ActSimCore *, act_chp_lang_t *);
static int max_pending_count;
static int max_stats;

Expand Down

0 comments on commit 6d8c458

Please sign in to comment.