From 501951f3d5ada07ff193eac6551984c473864626 Mon Sep 17 00:00:00 2001 From: sandeep Date: Wed, 12 Apr 2000 19:03:22 +0000 Subject: [PATCH] fixed the pointer value caching problem git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@232 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCBBlock.h | 1 + src/SDCCcse.c | 27 ++++++++++++++++++--------- src/SDCCcse.h | 2 +- src/SDCCdflow.c | 20 ++++++++++++++------ 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/SDCCBBlock.h b/src/SDCCBBlock.h index b8ad1aab..51d53726 100644 --- a/src/SDCCBBlock.h +++ b/src/SDCCBBlock.h @@ -61,6 +61,7 @@ typedef struct eBasicBlock { bitVect *usesDefs;/* which definitions are used in this block */ bitVect *ptrsSet; /* pointers assigned values in the block */ bitVect *inPtrsSet;/* in coming pointers assigned values */ + bitVect *ndompset; /* pointers set by non-dominating basic blocks */ set *addrOf ; /* symbols for which addres has been taken in the block */ bitVect *linds ; /* if loop exit this contains defNumbers for the inductions */ diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 52efaef7..fea12fb3 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -81,7 +81,7 @@ int pcseDef (void *item, va_list ap) /* replaceAllSymBySym - replaces all operands by operand in an */ /* instruction chain */ /*-----------------------------------------------------------------*/ -void replaceAllSymBySym (iCode *ic, operand *from , operand *to) +void replaceAllSymBySym (iCode *ic, operand *from , operand *to, bitVect **ndpset) { iCode *lic; @@ -122,12 +122,20 @@ void replaceAllSymBySym (iCode *ic, operand *from , operand *to) if (POINTER_SET(lic)) { bitVectUnSetBit (OP_USES(from),lic->key); OP_USES(to) = bitVectSetBit (OP_USES(to),lic->key); + + /* also check if the "from" was in the non-dominating + pointer sets and replace it with "to" in the bitVector */ + if (bitVectBitValue(*ndpset,from->key)) { + bitVectUnSetBit(*ndpset,from->key); + bitVectSetBit(*ndpset,to->key); + } + } else { bitVectUnSetBit (OP_DEFS(from),lic->key); OP_DEFS(to) = bitVectSetBit (OP_DEFS(to),lic->key); - } - siaddr = IC_RESULT(lic)->isaddr ; + } + siaddr = IC_RESULT(lic)->isaddr ; IC_RESULT(lic) = operandFromOperand(to); IC_RESULT(lic)->isaddr = siaddr ; } @@ -148,7 +156,7 @@ void replaceAllSymBySym (iCode *ic, operand *from , operand *to) siaddr = IC_LEFT(lic)->isaddr ; IC_LEFT(lic) = operandFromOperand(to); IC_LEFT(lic)->isaddr = siaddr ; - } + } } } @@ -183,7 +191,7 @@ DEFSETFUNC(removeFromInExprs) ebp->visited = 1; deleteItemIf(&ebp->inExprs,iCodeKeyIs,ic->key); if (ebp != cbp && !bitVectBitValue(cbp->domVect,ebp->bbnum)) - replaceAllSymBySym(ebp->sch,from,to); + replaceAllSymBySym(ebp->sch,from,to,&ebp->ndompset); applyToSet(ebp->succList,removeFromInExprs,ic,from,to,cbp); return 0; @@ -1318,7 +1326,8 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, pdic = NULL ; if (!( POINTER_GET(ic) && (IS_BITFIELD(OP_SYMBOL(IC_RESULT(ic))->etype) || - isOperandVolatile(IC_LEFT(ic),TRUE))) && + isOperandVolatile(IC_LEFT(ic),TRUE) || + bitVectBitValue(ebb->ndompset,IC_LEFT(ic)->key))) && ! ASSIGNMENT(ic) && IS_ITEMP(IC_RESULT(ic)) && ! computeOnly) { @@ -1333,7 +1342,7 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, if (IS_ITEMP(IC_RESULT(ic))) { /* replace in the remaining of this block */ - replaceAllSymBySym(ic->next,IC_RESULT(ic),IC_RESULT(pdic)); + replaceAllSymBySym(ic->next,IC_RESULT(ic),IC_RESULT(pdic),&ebb->ndompset); /* remove this iCode from inexpressions of all its successors, it cannot be in the in expressions of any of the predecessors */ @@ -1347,7 +1356,7 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, eBBlock *owner ; for (owner = setFirstItem(ic->movedFrom); owner ; owner = setNextItem(ic->movedFrom)) - replaceAllSymBySym(owner->sch,IC_RESULT(ic),IC_RESULT(pdic)); + replaceAllSymBySym(owner->sch,IC_RESULT(ic),IC_RESULT(pdic),&owner->ndompset); } pdic->movedFrom = unionSets(pdic->movedFrom,ic->movedFrom,THROW_NONE); } @@ -1399,7 +1408,7 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, /* if we find it then locally replace all references to the result with what we assigned */ if (pdop) { - replaceAllSymBySym(ic->next,IC_RESULT(ic),pdop); + replaceAllSymBySym(ic->next,IC_RESULT(ic),pdop,&ebb->ndompset); } } diff --git a/src/SDCCcse.h b/src/SDCCcse.h index faf0b3ad..e398dcc9 100644 --- a/src/SDCCcse.h +++ b/src/SDCCcse.h @@ -54,5 +54,5 @@ void ifxOptimize (iCode *,set *,int,eBBlock *,int *,eBBlock **,int); void unsetDefsAndUses ( iCode *) ; void updateSpillLocation ( iCode *ic); void setUsesDefs (operand *,bitVect *,bitVect *,bitVect **); -void replaceAllSymBySym (iCode *,operand *,operand *); +void replaceAllSymBySym (iCode *,operand *,operand *,bitVect **); #endif diff --git a/src/SDCCdflow.c b/src/SDCCdflow.c index 24d13c24..971ed998 100644 --- a/src/SDCCdflow.c +++ b/src/SDCCdflow.c @@ -97,18 +97,26 @@ DEFSETFUNC(mergeInExprs) /* if in the dominator list then */ if (bitVectBitValue(dest->domVect,ebp->bbnum) && dest != ebp) { /* if already present then intersect */ - if (!dest->inExprs && *firstTime) + if (!dest->inExprs && *firstTime) { dest->inExprs = setFromSet(ebp->outExprs); - else + /* copy the pointer set from the dominator */ + dest->inPtrsSet = bitVectCopy(ebp->ptrsSet); + dest->ndompset = bitVectCopy(ebp->ndompset); + } + else { dest->inExprs = intersectSets (dest->inExprs, ebp->outExprs, - THROW_DEST); - /* copy the pointer set from the dominator */ - dest->inPtrsSet = bitVectCopy(ebp->ptrsSet); + THROW_DEST); + dest->inPtrsSet = bitVectUnion(dest->inPtrsSet,ebp->ptrsSet); + dest->ndompset = bitVectUnion(dest->ndompset,ebp->ndompset); + } } - else + else { /* delete only if killed in this block */ deleteItemIf (&dest->inExprs,ifKilledInBlock, ebp); + /* union the ndompset with pointers set in this block*/ + dest->ndompset = bitVectUnion(dest->ndompset,ebp->ptrsSet); + } *firstTime = 0; -- 2.47.2