diff options
author | Teddy <[email protected]> | 2014-05-07 13:42:16 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2014-05-07 13:42:16 +0800 |
commit | 99e4b1f46c868dad37b6a9c30fd1210cb041a576 (patch) | |
tree | 0affa4459d9bcc37b388bceb255993acb42b22e3 | |
parent | 955a1c73f2cfd97058f5d850830386e2d3becabc (diff) |
fix bug in subexp opt
-rw-r--r-- | ssa.c | 24 | ||||
-rw-r--r-- | ssa.h | 1 |
2 files changed, 23 insertions, 2 deletions
@@ -2493,6 +2493,23 @@ CExpMap_t cexpmap_create(void) { return res; } +CExpMap_t cexpmap_dup(CExpMap_t cem) { + int i; + CExpMap_t res = cexpmap_create(); + for (i = 0; i < MAX_TABLE_SIZE; i++) + { + CENode *p, *t; + for (p = cem->head[i]; p; p = p->next) + { + t = NEW(CENode); + t->exp = p->exp; + t->next = res->head[i]; + res->head[i] = t; + } + } + return res; +} + int cexpmap_comp(CInst_t exp1, CInst_t exp2) { if (exp1->op != exp2->op) return 0; if (!copr_eq(exp1->src1, exp2->src1)) return 0; @@ -2581,8 +2598,11 @@ void subexp_elimination_(CBlock_t b, CExpMap_t cem) { } } for (e = dtree.head[b->id]; e; e = e->next) - subexp_elimination_(e->to, cem); - cexpmap_clear(cem); + { + CExpMap_t scem = cexpmap_dup(cem); + subexp_elimination_(e->to, scem); + cexpmap_destroy(scem); + } } void subexp_elimination(void) { @@ -137,6 +137,7 @@ typedef struct CExpMap { typedef CExpMap *CExpMap_t; CExpMap_t cexpmap_create(void); +CExpMap_t cexpmap_dup(CExpMap_t cem); unsigned int cexpmap_hash(CInst_t exp); int cexpmap_comp(CInst_t exp1, CInst_t exp2); void cexpmap_insert(CExpMap_t cem, CInst_t exp); |