Skip to content

Commit 3d8289d

Browse files
committed
Merge branch 'master' of https://github.com/rmanohar/actsim
2 parents 22fb4f3 + c1a1346 commit 3d8289d

File tree

3 files changed

+107
-19
lines changed

3 files changed

+107
-19
lines changed

chpgraph.cc

Lines changed: 105 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,69 @@ static Expr *expr_to_chp_expr (Expr *e, ActSimCore *s, int *flags)
11121112
return ret;
11131113
}
11141114

1115+
static int _get_detailed_costs (int &pos, const stateinfo_t *si)
1116+
{
1117+
char buf[10240];
1118+
char *nsname = NULL;
1119+
if (si->bnl->p->getns() != ActNamespace::Global()) {
1120+
nsname = si->bnl->p->getns()->Name();
1121+
}
1122+
if (nsname) {
1123+
snprintf (buf, 10240, "sim.chp.%s::%s.delays", nsname+2, si->bnl->p->getName());
1124+
FREE (nsname);
1125+
nsname = NULL;
1126+
}
1127+
else {
1128+
snprintf (buf, 10240, "sim.chp.%s.delays", si->bnl->p->getName());
1129+
}
1130+
if (!config_exists(buf)) {
1131+
return config_get_int ("sim.chp.default_delay");
1132+
}
1133+
int *dda_table = config_get_table_int (buf);
1134+
Assert (pos>=0, "huh?!");
1135+
int ret;
1136+
if (pos>=config_get_table_size(buf)) {
1137+
warning ("Detailed annotation table mismatch!");
1138+
ret = config_get_int ("sim.chp.default_delay");
1139+
}
1140+
else {
1141+
ret = int(dda_table[pos++]);
1142+
}
1143+
if (debug_metrics) {
1144+
fprintf (stderr, "delay : %d\n", ret);
1145+
}
1146+
return ret;
1147+
}
11151148

1116-
static chpsimstmt *gc_to_chpsim (act_chp_gc_t *gc, ActSimCore *s)
1149+
static void _dump_debug (act_chp_lang_t *c) {
1150+
if (debug_metrics) {
1151+
if (c->type == ACT_CHP_ASSIGN || c->type == ACT_CHP_ASSIGNSELF ||
1152+
c->type == ACT_CHP_RECV || c->type == ACT_CHP_SEND) {
1153+
fprintf (stderr, "\n basic : (");
1154+
}
1155+
if (c->type == ACT_CHP_SELECT || c->type == ACT_CHP_SELECT_NONDET) {
1156+
fprintf (stderr, "\n select : (");
1157+
}
1158+
if (c->type == ACT_CHP_COMMA) {
1159+
fprintf (stderr, "\n parallel : (");
1160+
}
1161+
if (c->type == ACT_CHP_LOOP || c->type == ACT_CHP_DOLOOP) {
1162+
fprintf (stderr, "\n loop : (");
1163+
}
1164+
chp_print(stderr, c);
1165+
fprintf (stderr, ") :: ");
1166+
}
1167+
return;
1168+
}
1169+
1170+
static void _get_detailed_costs (int &pos, const stateinfo_t *si, chpsimstmt *stmt)
1171+
{
1172+
stmt->bw_cost = 0;
1173+
stmt->energy_cost = 0;
1174+
stmt->delay_cost = _get_detailed_costs (pos, si);
1175+
}
1176+
1177+
static chpsimstmt *gc_to_chpsim (act_chp_gc_t *gc, ActSimCore *s, const int annotate_mode, int &dda_pos)
11171178
{
11181179
chpsimcond *tmp;
11191180
chpsimstmt *ret;
@@ -1124,7 +1185,7 @@ static chpsimstmt *gc_to_chpsim (act_chp_gc_t *gc, ActSimCore *s)
11241185

11251186
NEW (ret, chpsimstmt);
11261187
ret->type = CHPSIM_COND;
1127-
ret->delay_cost = 0;
1188+
ret->delay_cost = (annotate_mode) ? _get_detailed_costs(dda_pos, s->cursi()) : 0;
11281189
ret->energy_cost = 0;
11291190
ret->bw_cost = 0;
11301191
tmp = NULL;
@@ -1172,8 +1233,10 @@ chpsimgraph_info *ChpSimGraph::buildChpSimGraph (ActSimCore *sc,
11721233
if (!c) return NULL;
11731234

11741235
gi = new chpsimgraph_info;
1236+
int annotate_mode = config_get_int ("sim.chp.detailed_delay_annotation");
11751237

11761238
if (c->type == ACT_HSE_FRAGMENTS) {
1239+
if (annotate_mode!=0) { fatal_error("Detailed annotation not supported for HSE fragments"); }
11771240
int len = 0;
11781241
int i;
11791242
act_chp_lang_t *ch;
@@ -1192,7 +1255,8 @@ chpsimgraph_info *ChpSimGraph::buildChpSimGraph (ActSimCore *sc,
11921255
for (ch = c; ch; ch = ch->u.frag.next) {
11931256
b = hash_add (fH, ch->label);
11941257
b->i = i;
1195-
frags[i] = _buildChpSimGraph (sc, ch->u.frag.body, &nstop[i]);
1258+
int dummy = 0;
1259+
frags[i] = _buildChpSimGraph (sc, ch->u.frag.body, &nstop[i], annotate_mode, dummy);
11961260
i++;
11971261
}
11981262

@@ -1288,7 +1352,8 @@ chpsimgraph_info *ChpSimGraph::buildChpSimGraph (ActSimCore *sc,
12881352
return gi;
12891353
}
12901354
stop = new ChpSimGraph (sc);
1291-
gi->g = _buildChpSimGraph (sc, c, &stop);
1355+
int dda_pos = 0;
1356+
gi->g = _buildChpSimGraph (sc, c, &stop, annotate_mode, dda_pos);
12921357
gi->max_count = max_pending_count;
12931358
gi->max_stats = max_stats;
12941359
gi->e = NULL;
@@ -1393,7 +1458,7 @@ static void _get_costs (stateinfo_t *si, ActId *id, chpsimstmt *stmt)
13931458

13941459
ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
13951460
act_chp_lang_t *c,
1396-
ChpSimGraph **stop)
1461+
ChpSimGraph **stop, const int annotate_mode, int &dda_pos)
13971462
{
13981463
ChpSimGraph *ret = NULL;
13991464
ChpSimGraph *tmp2;
@@ -1412,7 +1477,7 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
14121477
if (list_length (c->u.semi_comma.cmd)== 1) {
14131478
ret = _buildChpSimGraph
14141479
(sc,
1415-
(act_chp_lang_t *)list_value (list_first (c->u.semi_comma.cmd)), stop);
1480+
(act_chp_lang_t *)list_value (list_first (c->u.semi_comma.cmd)), stop, annotate_mode, dda_pos);
14161481
_update_label (&labels, c->label, ret);
14171482
return ret;
14181483
}
@@ -1421,7 +1486,7 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
14211486
li; li = list_next (li)) {
14221487
cur_pending_count = count;
14231488
act_chp_lang_t *t = (act_chp_lang_t *) list_value (li);
1424-
ChpSimGraph *tmp = _buildChpSimGraph (sc, t, &tmp2);
1489+
ChpSimGraph *tmp = _buildChpSimGraph (sc, t, &tmp2, annotate_mode, dda_pos);
14251490
if (tmp) {
14261491
if (!ret) {
14271492
ret = tmp;
@@ -1441,7 +1506,7 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
14411506
if (list_length (c->u.semi_comma.cmd)== 1) {
14421507
ret = _buildChpSimGraph
14431508
(sc,
1444-
(act_chp_lang_t *)list_value (list_first (c->u.semi_comma.cmd)), stop);
1509+
(act_chp_lang_t *)list_value (list_first (c->u.semi_comma.cmd)), stop, annotate_mode, dda_pos);
14451510
_update_label (&labels, c->label, ret);
14461511
return ret;
14471512
}
@@ -1462,16 +1527,17 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
14621527
for (listitem_t *li = list_first (c->u.semi_comma.cmd);
14631528
li; li = list_next (li)) {
14641529
ret->all[i] = _buildChpSimGraph (sc,
1465-
(act_chp_lang_t *)list_value (li), &tmp2);
1530+
(act_chp_lang_t *)list_value (li), &tmp2, annotate_mode, dda_pos);
14661531
if (ret->all[i]) {
14671532
tmp2->next = *stop;
14681533
count++;
14691534
}
14701535
i++;
14711536
}
14721537
if (count > 0) {
1538+
_dump_debug (c);
14731539
NEW (ret->stmt, chpsimstmt);
1474-
ret->stmt->delay_cost = 0;
1540+
ret->stmt->delay_cost = (annotate_mode) ? _get_detailed_costs(dda_pos, sc->cursi()) : 0;
14751541
ret->stmt->energy_cost = 0;
14761542
ret->stmt->bw_cost = 0;
14771543
ret->stmt->type = CHPSIM_FORK;
@@ -1492,7 +1558,8 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
14921558
case ACT_CHP_SELECT_NONDET:
14931559
case ACT_CHP_LOOP:
14941560
ret = new ChpSimGraph (sc);
1495-
ret->stmt = gc_to_chpsim (c->u.gc, sc);
1561+
_dump_debug (c);
1562+
ret->stmt = gc_to_chpsim (c->u.gc, sc, annotate_mode, dda_pos);
14961563
if (c->type == ACT_CHP_LOOP) {
14971564
ret->stmt->type = CHPSIM_LOOP;
14981565
}
@@ -1516,7 +1583,7 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
15161583
count = cur_pending_count;
15171584
for (act_chp_gc_t *gc = c->u.gc; gc; gc = gc->next) {
15181585
cur_pending_count = count;
1519-
ret->all[i] = _buildChpSimGraph (sc, gc->s, &tmp2);
1586+
ret->all[i] = _buildChpSimGraph (sc, gc->s, &tmp2, annotate_mode, dda_pos);
15201587
if (ret->all[i]) {
15211588
if (c->type == ACT_CHP_LOOP) {
15221589
/* loop back */
@@ -1543,7 +1610,7 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
15431610
case ACT_CHP_DOLOOP:
15441611
{
15451612
ChpSimGraph *ntmp;
1546-
ChpSimGraph *nret = _buildChpSimGraph (sc, c->u.gc->s, &ntmp);
1613+
ChpSimGraph *nret = _buildChpSimGraph (sc, c->u.gc->s, &ntmp, annotate_mode, dda_pos);
15471614

15481615
ret = new ChpSimGraph (sc);
15491616

@@ -1552,12 +1619,13 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
15521619
ntmp = nret;
15531620
}
15541621
ntmp->next = ret;
1555-
ret->stmt = gc_to_chpsim (c->u.gc, sc);
1622+
_dump_debug (c);
1623+
ret->stmt = gc_to_chpsim (c->u.gc, sc, annotate_mode, dda_pos);
15561624
ret->stmt->type = CHPSIM_LOOP;
15571625
(*stop) = new ChpSimGraph (sc);
15581626
ret->next = (*stop);
15591627
MALLOC (ret->all, ChpSimGraph *, 1);
1560-
ret->all[0] = _buildChpSimGraph (sc, c->u.gc->s, &tmp2);
1628+
ret->all[0] = _buildChpSimGraph (sc, c->u.gc->s, &tmp2, annotate_mode, dda_pos);
15611629
if (!ret->all[0]) {
15621630
ret->all[0] = _gen_nop (sc);
15631631
tmp2 = ret->all[0];
@@ -1590,7 +1658,13 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
15901658

15911659
ret = new ChpSimGraph (sc);
15921660
NEW (ret->stmt, chpsimstmt);
1593-
_get_costs (sc->cursi(), c->u.comm.chan, ret->stmt);
1661+
if (annotate_mode) {
1662+
_dump_debug (c);
1663+
_get_detailed_costs (dda_pos, sc->cursi(), ret->stmt);
1664+
}
1665+
else {
1666+
_get_costs (sc->cursi(), c->u.comm.chan, ret->stmt);
1667+
}
15941668
ret->stmt->type = CHPSIM_SEND;
15951669
ret->stmt->u.sendrecv.is_struct = ch_struct;
15961670
if (ch_struct == 0) {
@@ -1685,7 +1759,13 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
16851759
}
16861760
ret = new ChpSimGraph (sc);
16871761
NEW (ret->stmt, chpsimstmt);
1688-
_get_costs (sc->cursi(), c->u.comm.chan, ret->stmt);
1762+
if (annotate_mode) {
1763+
_dump_debug (c);
1764+
_get_detailed_costs (dda_pos, sc->cursi(), ret->stmt);
1765+
}
1766+
else {
1767+
_get_costs (sc->cursi(), c->u.comm.chan, ret->stmt);
1768+
}
16891769
ret->stmt->type = CHPSIM_RECV;
16901770
if (ch_struct) {
16911771
ret->stmt->u.sendrecv.is_struct = 1;
@@ -1859,7 +1939,14 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc,
18591939

18601940
ret = new ChpSimGraph (sc);
18611941
NEW (ret->stmt, chpsimstmt);
1862-
_get_costs (sc->cursi(), c->u.assign.id, ret->stmt);
1942+
1943+
if (annotate_mode) {
1944+
_dump_debug (c);
1945+
_get_detailed_costs (dda_pos, sc->cursi(), ret->stmt);
1946+
}
1947+
else {
1948+
_get_costs (sc->cursi(), c->u.assign.id, ret->stmt);
1949+
}
18631950
ret->stmt->type = CHPSIM_ASSIGN;
18641951
if (TypeFactory::isStructure (it)) {
18651952
ret->stmt->u.assign.is_struct = 1;

chpsim.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ChpSimGraph {
172172
static void recordChannel (ActSimCore *, ChpSim *, act_chp_lang_t *);
173173
private:
174174
static ChpSimGraph *_buildChpSimGraph (ActSimCore *,
175-
act_chp_lang_t *, ChpSimGraph **stop);
175+
act_chp_lang_t *, ChpSimGraph **stop, int, int&);
176176
static int cur_pending_count;
177177

178178
};

main.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,7 @@ int main (int argc, char **argv)
18381838
config_set_default_real ("sim.chp.default_leakage", 0);
18391839
config_set_default_int ("sim.chp.default_area", 0);
18401840
config_set_default_int ("sim.chp.debug_metrics", 0);
1841+
config_set_default_int ("sim.chp.detailed_delay_annotation", 0);
18411842
config_set_int ("net.emit_parasitics", 1);
18421843

18431844
/* initialize ACT library */

0 commit comments

Comments
 (0)