From 99e4b1f46c868dad37b6a9c30fd1210cb041a576 Mon Sep 17 00:00:00 2001 From: Teddy Date: Wed, 7 May 2014 13:42:16 +0800 Subject: fix bug in subexp opt --- ssa.c | 24 ++++++++++++++++++++++-- ssa.h | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ssa.c b/ssa.c index ff7c0a7..af1311f 100644 --- a/ssa.c +++ b/ssa.c @@ -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) { diff --git a/ssa.h b/ssa.h index 68ea774..2ad86cd 100644 --- a/ssa.h +++ b/ssa.h @@ -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); -- cgit v1.2.3