1 /*-------------------------------------------------------------------------
2 SDCCcse.c - source file for Common Subexpressions and other utility
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding!
23 -------------------------------------------------------------------------*/
28 /*-----------------------------------------------------------------*/
29 /* newCseDef - new cseDef */
30 /*-----------------------------------------------------------------*/
32 newCseDef (operand * sym, iCode * ic)
37 cdp = Safe_alloc (sizeof (cseDef));
48 /*-----------------------------------------------------------------*/
49 /* int isCseDefEqual - two definitions are equal */
50 /*-----------------------------------------------------------------*/
52 isCseDefEqual (void *vsrc, void *vdest)
60 return (src->key == dest->key &&
61 src->diCode == dest->diCode);
65 /*-----------------------------------------------------------------*/
66 /* pcseDef - in the cseDef */
67 /*-----------------------------------------------------------------*/
69 pcseDef (void *item, va_list ap)
77 fprintf (stdout, "**null op**");
78 printOperand (cdp->sym, stdout);
79 icTab = getTableEntry (cdp->diCode->op);
80 icTab->iCodePrint (stdout, cdp->diCode, icTab->printName);
84 void ReplaceOpWithCheaperOp(operand **op, operand *cop) {
86 printf ("ReplaceOpWithCheaperOp (%s:%d with %s:%d): ",
87 OP_SYMBOL((*op))->name, OP_SYMBOL((*op))->isreqv,
88 OP_SYMBOL(cop)->name, OP_SYMBOL(cop)->isreqv);
89 // if op is a register equivalent
90 if (IS_ITEMP(cop) && OP_SYMBOL((*op))->isreqv) {
91 operand **rop = &OP_SYMBOL((*op))->usl.spillLoc->reqv;
92 if (isOperandEqual(*rop, *op)) {
95 OP_SYMBOL((*op))->isreqv=0;
96 OP_SYMBOL(cop)->isreqv=1;
106 /*-----------------------------------------------------------------*/
107 /* replaceAllSymBySym - replaces all operands by operand in an */
108 /* instruction chain */
109 /*-----------------------------------------------------------------*/
111 replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset)
115 for (lic = ic; lic; lic = lic->next)
119 /* do the special cases first */
123 IC_COND (lic)->key == from->key)
126 bitVectUnSetBit (OP_USES (from), lic->key);
127 OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
128 siaddr = IC_COND (lic)->isaddr;
129 IC_COND (lic) = operandFromOperand (to);
130 IC_COND (lic)->isaddr = siaddr;
136 if (lic->op == JUMPTABLE)
139 IC_JTCOND (lic)->key == from->key)
142 bitVectUnSetBit (OP_USES (from), lic->key);
143 OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
144 siaddr = IC_COND (lic)->isaddr;
145 IC_JTCOND (lic) = operandFromOperand (to);
146 IC_JTCOND (lic)->isaddr = siaddr;
153 IC_RESULT (lic) && IC_RESULT (lic)->key == from->key)
155 /* maintain du chains */
156 if (POINTER_SET (lic))
158 bitVectUnSetBit (OP_USES (from), lic->key);
159 OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
161 /* also check if the "from" was in the non-dominating
162 pointer sets and replace it with "to" in the bitVector */
163 if (bitVectBitValue (*ndpset, from->key))
165 bitVectUnSetBit (*ndpset, from->key);
166 bitVectSetBit (*ndpset, to->key);
172 bitVectUnSetBit (OP_DEFS (from), lic->key);
173 OP_DEFS(to)=bitVectSetBit (OP_DEFS (to), lic->key);
175 siaddr = IC_RESULT (lic)->isaddr;
176 IC_RESULT (lic) = operandFromOperand (to);
177 IC_RESULT (lic)->isaddr = siaddr;
181 IC_RIGHT (lic) && IC_RIGHT (lic)->key == from->key)
183 bitVectUnSetBit (OP_USES (from), lic->key);
184 OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
185 siaddr = IC_RIGHT (lic)->isaddr;
186 IC_RIGHT (lic) = operandFromOperand (to);
187 IC_RIGHT (lic)->isaddr = siaddr;
191 IC_LEFT (lic) && IC_LEFT (lic)->key == from->key)
193 bitVectUnSetBit (OP_USES (from), lic->key);
194 OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
195 siaddr = IC_LEFT (lic)->isaddr;
196 IC_LEFT (lic) = operandFromOperand (to);
197 IC_LEFT (lic)->isaddr = siaddr;
202 /*-----------------------------------------------------------------*/
203 /* iCodeKeyIs - if the icode keys match then return 1 */
204 /*-----------------------------------------------------------------*/
205 DEFSETFUNC (iCodeKeyIs)
210 if (cdp->diCode->key == key)
216 /*-----------------------------------------------------------------*/
217 /* removeFromInExprs - removes an icode from inexpressions */
218 /*-----------------------------------------------------------------*/
219 DEFSETFUNC (removeFromInExprs)
223 V_ARG (operand *, from);
224 V_ARG (operand *, to);
225 V_ARG (eBBlock *, cbp);
231 deleteItemIf (&ebp->inExprs, iCodeKeyIs, ic->key);
232 if (ebp != cbp && !bitVectBitValue (cbp->domVect, ebp->bbnum))
233 replaceAllSymBySym (ebp->sch, from, to, &ebp->ndompset);
235 applyToSet (ebp->succList, removeFromInExprs, ic, from, to, cbp);
239 /*-----------------------------------------------------------------*/
240 /* isGlobalInNearSpace - return TRUE if valriable is a globalin data */
241 /*-----------------------------------------------------------------*/
243 isGlobalInNearSpace (operand * op)
245 sym_link *type = getSpec (operandType (op));
246 /* this is 8051 specific: optimization
247 suggested by Jean-Louis VERN, with 8051s we have no
248 advantage of putting variables in near space into
250 if (isOperandGlobal (op) && !IN_FARSPACE (SPEC_OCLS (type)) &&
251 IN_DIRSPACE (SPEC_OCLS (type)))
257 /*-----------------------------------------------------------------*/
258 /* findCheaperOp - cseBBlock support routine, will check to see if */
259 /* we have a operand previously defined */
260 /*-----------------------------------------------------------------*/
261 DEFSETFUNC (findCheaperOp)
264 V_ARG (operand *, cop);
265 V_ARG (operand **, opp);
266 V_ARG (int, checkSign);
268 /* if we have already found it */
272 /* not found it yet check if this is the one */
273 /* and this is not the defining one */
274 if (cop->key == cdp->key)
277 /* do a special check this will help in */
278 /* constant propagation & dead code elim */
279 /* for assignments only */
280 if (cdp->diCode->op == '=') {
281 /* if the result is volatile then return result */
282 if (IS_OP_VOLATILE (IC_RESULT (cdp->diCode)))
283 *opp = IC_RESULT (cdp->diCode);
285 /* if this is a straight assignment and
286 left is a temp then prefer the temporary to the
288 if (!POINTER_SET (cdp->diCode) &&
289 IS_ITEMP (IC_RESULT (cdp->diCode)) &&
290 IS_TRUE_SYMOP (IC_RIGHT (cdp->diCode)))
291 *opp = IC_RESULT (cdp->diCode);
293 /* if straight assignement && and both
294 are temps then prefer the one that
295 will not need extra space to spil, also
296 take into consideration if right side
297 an induction variable
299 if (!POINTER_SET (cdp->diCode) &&
300 IS_ITEMP (IC_RESULT (cdp->diCode)) &&
301 IS_ITEMP (IC_RIGHT (cdp->diCode)) &&
302 !OP_SYMBOL (IC_RIGHT (cdp->diCode))->isind &&
303 !OP_SYMBOL(IC_RIGHT (cdp->diCode))->isreqv &&
304 ((!SPIL_LOC (IC_RIGHT (cdp->diCode)) &&
305 SPIL_LOC (IC_RESULT (cdp->diCode))) ||
306 (SPIL_LOC (IC_RESULT (cdp->diCode)) &&
307 SPIL_LOC (IC_RESULT (cdp->diCode)) ==
308 SPIL_LOC (IC_RIGHT (cdp->diCode)))))
309 *opp = IC_RESULT (cdp->diCode);
311 *opp = IC_RIGHT (cdp->diCode);
315 *opp = IC_RESULT (cdp->diCode);
318 /* if this is an assign to a temp. then check
319 if the right side is this then return this */
320 if (IS_TRUE_SYMOP (cop) &&
321 cdp->diCode->op == '=' &&
322 !POINTER_SET (cdp->diCode) &&
323 cop->key == IC_RIGHT (cdp->diCode)->key &&
324 !isGlobalInNearSpace (IC_RIGHT (cdp->diCode)) &&
325 IS_ITEMP (IC_RESULT (cdp->diCode)))
326 *opp = IC_RESULT (cdp->diCode);
329 (isOperandLiteral(*opp) || !checkSign ||
331 IS_SPEC(operandType (cop)) && IS_SPEC(operandType (*opp)) &&
332 (SPEC_USIGN(operandType (cop))==SPEC_USIGN(operandType (*opp)) &&
333 (SPEC_LONG(operandType (cop))==SPEC_LONG(operandType (*opp)))))))
336 if ((isGlobalInNearSpace (cop) &&
337 !isOperandLiteral (*opp)) ||
338 isOperandVolatile (*opp, FALSE)
345 if (cop->key == (*opp)->key)
351 if ((*opp)->isaddr != cop->isaddr && IS_ITEMP (cop))
353 *opp = operandFromOperand (*opp);
354 (*opp)->isaddr = cop->isaddr;
357 if (IS_SPEC(operandType (cop)) && IS_SPEC(operandType (*opp)) &&
358 SPEC_NOUN(operandType(cop)) != SPEC_NOUN(operandType(*opp)))
360 // special case: we can make an unsigned char literal
361 // into an int literal with no cost.
362 if (isOperandLiteral(*opp)
363 && SPEC_NOUN(operandType(*opp)) == V_CHAR
364 && SPEC_NOUN(operandType(cop)) == V_INT)
366 *opp = operandFromOperand (*opp);
367 SPEC_NOUN(operandType(*opp)) = V_INT;
385 /*-----------------------------------------------------------------*/
386 /* findPointerSet - finds the right side of a pointer set op */
387 /*-----------------------------------------------------------------*/
388 DEFSETFUNC (findPointerSet)
391 V_ARG (operand *, op);
392 V_ARG (operand **, opp);
393 V_ARG (operand *, rop);
395 if (POINTER_SET (cdp->diCode) &&
396 IC_RESULT (cdp->diCode)->key == op->key &&
397 !isOperandVolatile (IC_RESULT (cdp->diCode), TRUE) &&
398 !isOperandVolatile (IC_RIGHT (cdp->diCode), TRUE) &&
399 getSize (operandType (IC_RIGHT (cdp->diCode))) ==
400 getSize (operandType (rop)))
402 *opp = IC_RIGHT (cdp->diCode);
409 /*-----------------------------------------------------------------*/
410 /* findPrevIc - cseBBlock support function will return the iCode */
411 /* which matches the current one */
412 /*-----------------------------------------------------------------*/
413 DEFSETFUNC (findPrevIc)
417 V_ARG (iCode **, icp);
419 /* if already found */
423 /* if the iCodes are the same */
424 if (isiCodeEqual (ic, cdp->diCode) &&
425 isOperandEqual (cdp->sym, IC_RESULT (cdp->diCode)))
431 /* if iCodes are not the same */
432 /* see the operands maybe interchanged */
433 if (ic->op == cdp->diCode->op &&
434 (ic->op == '+' || ic->op == '*') &&
435 isOperandEqual (IC_LEFT (ic), IC_RIGHT (cdp->diCode)) &&
436 isOperandEqual (IC_RIGHT (ic), IC_LEFT (cdp->diCode)))
445 /*-------------------------------------------------------------------*/
446 /* ifAssignedFromGlobal - if definition is an assignment from global */
447 /*-------------------------------------------------------------------*/
448 DEFSETFUNC (ifAssignedFromGlobal)
451 iCode *dic=cdp->diCode;
453 if (dic->op=='=' && isOperandGlobal(IC_RIGHT(dic))) {
459 /*-----------------------------------------------------------------*/
460 /* ifDefGlobal - if definition is global */
461 /*-----------------------------------------------------------------*/
462 DEFSETFUNC (ifDefGlobal)
466 return (isOperandGlobal (cdp->sym));
469 /*-----------------------------------------------------------------*/
470 /* ifAnyGetPointer - if get pointer icode */
471 /*-----------------------------------------------------------------*/
472 DEFSETFUNC (ifAnyGetPointer)
476 if (cdp->diCode && POINTER_GET (cdp->diCode))
481 /*-----------------------------------------------------------------*/
482 /* ifOperandsHave - if any of the operand are the same as this */
483 /*-----------------------------------------------------------------*/
484 DEFSETFUNC (ifOperandsHave)
487 V_ARG (operand *, op);
490 if (IC_LEFT (cdp->diCode) &&
491 IS_SYMOP (IC_LEFT (cdp->diCode)) &&
492 IC_LEFT (cdp->diCode)->key == op->key)
495 if (IC_RIGHT (cdp->diCode) &&
496 IS_SYMOP (IC_RIGHT (cdp->diCode)) &&
497 IC_RIGHT (cdp->diCode)->key == op->key)
500 /* or if any of the operands are volatile */
501 if (IC_LEFT (cdp->diCode) &&
502 IS_OP_VOLATILE (IC_LEFT (cdp->diCode)))
505 if (IC_RIGHT (cdp->diCode) &&
506 IS_OP_VOLATILE (IC_RIGHT (cdp->diCode)))
510 if (IC_RESULT (cdp->diCode) &&
511 IS_OP_VOLATILE (IC_RESULT (cdp->diCode)))
517 /*-----------------------------------------------------------------*/
518 /* ifDefSymIs - if a definition is found in the set */
519 /*-----------------------------------------------------------------*/
521 ifDefSymIs (set * cseSet, operand * sym)
526 if (!sym || !IS_SYMOP (sym))
528 for (sl = cseSet; sl; sl = sl->next)
531 if (loop->sym->key == sym->key)
538 /*-----------------------------------------------------------------*/
539 /* ifDefSymIsX - will return 1 if the symbols match */
540 /*-----------------------------------------------------------------*/
541 DEFSETFUNC (ifDefSymIsX)
544 V_ARG (operand *, op);
547 return cdp->sym->key == op->key;
549 return (isOperandEqual (cdp->sym, op));
554 /*-----------------------------------------------------------------*/
555 /* ifDiCodeIs - returns truw if diCode is same */
556 /*-----------------------------------------------------------------*/
558 ifDiCodeIs (set * cseSet, iCode * ic)
566 for (sl = cseSet; sl; sl = sl->next)
569 if (loop->diCode == ic)
576 /*-----------------------------------------------------------------*/
577 /* ifPointerGet - returns true if the icode is pointer get sym */
578 /*-----------------------------------------------------------------*/
579 DEFSETFUNC (ifPointerGet)
582 V_ARG (operand *, op);
583 iCode *dic = cdp->diCode;
584 operand *left = IC_LEFT (cdp->diCode);
586 if (POINTER_GET (dic) && left->key == op->key)
592 /*-----------------------------------------------------------------*/
593 /* ifPointerSet - returns true if the icode is pointer set sym */
594 /*-----------------------------------------------------------------*/
595 DEFSETFUNC (ifPointerSet)
598 V_ARG (operand *, op);
600 if (POINTER_SET (cdp->diCode) &&
601 IC_RESULT (cdp->diCode)->key == op->key)
607 /*-----------------------------------------------------------------*/
608 /* ifDiCodeIsX - will return 1 if the symbols match */
609 /*-----------------------------------------------------------------*/
610 DEFSETFUNC (ifDiCodeIsX)
615 return cdp->diCode == ic;
619 /*-----------------------------------------------------------------*/
620 /* findBackwardDef - scan backwards to find deinition of operand */
621 /*-----------------------------------------------------------------*/
622 iCode *findBackwardDef(operand *op,iCode *ic)
626 for (lic = ic; lic ; lic = lic->prev) {
627 if (IC_RESULT(lic) && isOperandEqual(op,IC_RESULT(lic)))
633 /*-----------------------------------------------------------------*/
634 /* algebraicOpts - does some algebraic optimizations */
635 /*-----------------------------------------------------------------*/
637 algebraicOpts (iCode * ic)
639 /* we don't deal with the following iCodes
650 /* if both operands present & ! IFX */
651 /* then if they are both literal we */
652 /* perform the operation right now */
653 if (IC_RESULT (ic) &&
656 IS_OP_LITERAL (IC_LEFT (ic)) &&
657 IS_OP_LITERAL (IC_RIGHT (ic)))
660 IC_RIGHT (ic) = operandOperation (IC_LEFT (ic),
663 operandType (IC_RESULT (ic)));
666 SET_RESULT_RIGHT (ic);
670 /* if not ifx & only one operand present */
671 if (IC_RESULT (ic) &&
673 IS_OP_LITERAL (IC_LEFT (ic)) &&
677 IC_RIGHT (ic) = operandOperation (IC_LEFT (ic),
680 operandType (IC_RESULT (ic)));
683 SET_RESULT_RIGHT (ic);
688 /* a special case : or in short a kludgy solution will think
689 about a better solution over a glass of wine someday */
690 if (ic->op == GET_VALUE_AT_ADDRESS)
693 if (IS_ITEMP (IC_RESULT (ic)) &&
694 IS_TRUE_SYMOP (IC_LEFT (ic)))
698 IC_RIGHT (ic) = operandFromOperand (IC_LEFT (ic));
699 IC_RIGHT (ic)->isaddr = 0;
701 IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic));
702 IC_RESULT (ic)->isaddr = 0;
703 setOperandType (IC_RESULT (ic), operandType (IC_RIGHT (ic)));
707 if (IS_ITEMP (IC_LEFT (ic)) &&
708 IS_ITEMP (IC_RESULT (ic)) &&
709 /* !OP_SYMBOL(IC_RESULT(ic))->isreqv && */
710 /* !OP_SYMBOL(IC_LEFT(ic))->isreqv && */
711 !IC_LEFT (ic)->isaddr)
714 IC_RIGHT (ic) = operandFromOperand (IC_LEFT (ic));
715 IC_RIGHT (ic)->isaddr = 0;
716 IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic));
717 IC_RESULT (ic)->isaddr = 0;
725 /* depending on the operation */
729 /* if adding the same thing change to left shift by 1 */
730 if (IC_LEFT (ic)->key == IC_RIGHT (ic)->key &&
731 !IS_FLOAT (operandType (IC_RESULT (ic))))
734 IC_RIGHT (ic) = operandFromLit (1);
737 /* if addition then check if one of them is a zero */
738 /* if yes turn it into assignmnt */
739 if (IS_OP_LITERAL (IC_LEFT (ic)) &&
740 operandLitValue (IC_LEFT (ic)) == 0.0)
745 SET_ISADDR (IC_RESULT (ic), 0);
746 SET_ISADDR (IC_RIGHT (ic), 0);
749 if (IS_OP_LITERAL (IC_RIGHT (ic)) &&
750 operandLitValue (IC_RIGHT (ic)) == 0.0)
754 IC_RIGHT (ic) = IC_LEFT (ic);
756 SET_ISADDR (IC_RIGHT (ic), 0);
757 SET_ISADDR (IC_RESULT (ic), 0);
762 /* if subtracting the the same thing then zero */
763 if (IC_LEFT (ic)->key == IC_RIGHT (ic)->key)
766 IC_RIGHT (ic) = operandFromLit (0);
768 IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic));
769 IC_RESULT (ic)->isaddr = 0;
773 /* if subtraction then check if one of the operand */
774 /* is zero then depending on which operand change */
775 /* to assignment or unary minus */
776 if (IS_OP_LITERAL (IC_RIGHT (ic)) &&
777 operandLitValue (IC_RIGHT (ic)) == 0.0)
779 /* right size zero change to assignment */
781 IC_RIGHT (ic) = IC_LEFT (ic);
783 SET_ISADDR (IC_RIGHT (ic), 0);
784 SET_ISADDR (IC_RESULT (ic), 0);
787 if (IS_OP_LITERAL (IC_LEFT (ic)) &&
788 operandLitValue (IC_LEFT (ic)) == 0.0)
790 /* left zero turn into an unary minus */
792 IC_LEFT (ic) = IC_RIGHT (ic);
793 IC_RIGHT (ic) = NULL;
797 /* if multiplication then check if either of */
798 /* them is zero then the result is zero */
799 /* if either of them is one then result is */
802 if (IS_OP_LITERAL (IC_LEFT (ic)))
805 if (operandLitValue (IC_LEFT (ic)) == 0.0)
808 IC_RIGHT (ic) = IC_LEFT (ic);
810 SET_RESULT_RIGHT (ic);
813 if (operandLitValue (IC_LEFT (ic)) == 1.0)
817 SET_RESULT_RIGHT (ic);
822 if (IS_OP_LITERAL (IC_RIGHT (ic)))
825 if (operandLitValue (IC_RIGHT (ic)) == 0.0)
829 SET_RESULT_RIGHT (ic);
833 if (operandLitValue (IC_RIGHT (ic)) == 1.0)
836 IC_RIGHT (ic) = IC_LEFT (ic);
838 SET_RESULT_RIGHT (ic);
844 /* if division by self then 1 */
845 if (IC_LEFT (ic)->key == IC_RIGHT (ic)->key)
848 IC_RIGHT (ic) = operandFromLit (1);
850 IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic));
851 IC_RESULT (ic)->isaddr = 0;
854 /* if this is a division then check if right */
855 /* is one then change it to an assignment */
856 if (IS_OP_LITERAL (IC_RIGHT (ic)) &&
857 operandLitValue (IC_RIGHT (ic)) == 1.0)
861 IC_RIGHT (ic) = IC_LEFT (ic);
863 SET_RESULT_RIGHT (ic);
867 /* if both are the same for an comparison operators */
871 if (isOperandEqual (IC_LEFT (ic), IC_RIGHT (ic)))
874 IC_RIGHT (ic) = operandFromLit (1);
876 SET_RESULT_RIGHT (ic);
882 if (isOperandEqual (IC_LEFT (ic), IC_RIGHT (ic)))
885 IC_RIGHT (ic) = operandFromLit (0);
887 SET_RESULT_RIGHT (ic);
892 sym_link *otype = operandType(IC_RIGHT(ic));
893 sym_link *ctype = operandType(IC_LEFT(ic));
894 /* if this is a cast of a literal value */
895 if (IS_OP_LITERAL (IC_RIGHT (ic)) &&
896 !(IS_GENPTR(ctype) && (IS_PTR(otype) && !IS_GENPTR(otype)))) {
899 operandFromValue (valCastLiteral (operandType (IC_LEFT (ic)),
900 operandLitValue (IC_RIGHT (ic))));
902 SET_ISADDR (IC_RESULT (ic), 0);
904 /* if casting to the same */
905 if (compareType (operandType (IC_RESULT (ic)),
906 operandType (IC_RIGHT (ic))) == 1) {
909 SET_ISADDR (IC_RESULT (ic), 0);
914 if (IS_OP_LITERAL (IC_LEFT (ic)))
918 (operandLitValue (IC_LEFT (ic)) == 0 ?
919 operandFromLit (1) : operandFromLit (0));
921 SET_ISADDR (IC_RESULT (ic), 0);
927 #define OTHERS_PARM(s) (s->_isparm && !s->ismyparm)
928 /*-----------------------------------------------------------------*/
929 /* updateSpillLocation - keeps track of register spill location */
930 /*-----------------------------------------------------------------*/
932 updateSpillLocation (iCode * ic, int induction)
936 if (POINTER_SET (ic))
942 /* for the form true_symbol := iTempNN */
943 if (ASSIGN_ITEMP_TO_SYM (ic) &&
944 !SPIL_LOC (IC_RIGHT (ic))) {
946 setype = getSpec (operandType (IC_RESULT (ic)));
948 if (!OP_SYMBOL(IC_RIGHT (ic))->noSpilLoc &&
949 !IS_VOLATILE (setype) &&
950 !IN_FARSPACE (SPEC_OCLS (setype)) &&
951 !OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic))))
953 wassert(IS_SYMOP(IC_RESULT (ic)));
954 wassert(IS_SYMOP(IC_RIGHT (ic)));
955 SPIL_LOC (IC_RIGHT (ic)) =
956 IC_RESULT (ic)->operand.symOperand;
961 #if 0 /* this needs furthur investigation can save a lot of code */
962 if (ASSIGN_SYM_TO_ITEMP(ic) &&
963 !SPIL_LOC(IC_RESULT(ic))) {
964 if (!OTHERS_PARM (OP_SYMBOL (IC_RIGHT (ic))))
965 SPIL_LOC (IC_RESULT (ic)) =
966 IC_RIGHT (ic)->operand.symOperand;
969 if (ASSIGN_ITEMP_TO_ITEMP (ic)) {
971 if (!SPIL_LOC (IC_RIGHT (ic)) &&
972 !bitVectBitsInCommon (OP_DEFS (IC_RIGHT (ic)), OP_USES (IC_RESULT (ic))) &&
973 OP_SYMBOL (IC_RESULT (ic))->isreqv) {
975 setype = getSpec (operandType (IC_RESULT (ic)));
977 if (!OP_SYMBOL(IC_RIGHT (ic))->noSpilLoc &&
978 !IS_VOLATILE (setype) &&
979 !IN_FARSPACE (SPEC_OCLS (setype)) &&
980 !OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic))))
982 SPIL_LOC (IC_RIGHT (ic)) =
983 SPIL_LOC (IC_RESULT (ic));
985 /* special case for inductions */
987 OP_SYMBOL(IC_RIGHT(ic))->isreqv &&
988 !OP_SYMBOL(IC_RESULT (ic))->noSpilLoc &&
989 !SPIL_LOC(IC_RESULT(ic))) {
990 SPIL_LOC (IC_RESULT (ic)) = SPIL_LOC (IC_RIGHT (ic));
994 /*-----------------------------------------------------------------*/
995 /* setUsesDef - sets the uses def bitvector for a given operand */
996 /*-----------------------------------------------------------------*/
998 setUsesDefs (operand * op, bitVect * bdefs,
999 bitVect * idefs, bitVect ** oud)
1001 /* compute the definitions alive at this point */
1002 bitVect *adefs = bitVectUnion (bdefs, idefs);
1004 /* of these definitions find the ones that are */
1005 /* for this operand */
1006 adefs = bitVectIntersect (adefs, OP_DEFS (op));
1008 /* these are the definitions that this operand can use */
1009 op->usesDefs = adefs;
1011 /* the out defs is an union */
1012 *oud = bitVectUnion (*oud, adefs);
1015 /*-----------------------------------------------------------------*/
1016 /* unsetDefsAndUses - clear this operation for the operands */
1017 /*-----------------------------------------------------------------*/
1019 unsetDefsAndUses (iCode * ic)
1021 if (ic->op == JUMPTABLE)
1024 /* take away this definition from the def chain of the */
1025 /* result & take away from use set of the operands */
1028 /* turn off def set */
1029 if (IS_SYMOP (IC_RESULT (ic)))
1031 if (!POINTER_SET (ic))
1032 bitVectUnSetBit (OP_DEFS (IC_RESULT (ic)), ic->key);
1034 bitVectUnSetBit (OP_USES (IC_RESULT (ic)), ic->key);
1036 /* turn off the useSet for the operands */
1037 if (IS_SYMOP (IC_LEFT (ic)))
1038 bitVectUnSetBit (OP_USES (IC_LEFT (ic)), ic->key);
1040 if (IS_SYMOP (IC_RIGHT (ic)))
1041 bitVectUnSetBit (OP_USES (IC_RIGHT (ic)), ic->key);
1044 /* must be ifx turn off the use */ if (IS_SYMOP (IC_COND (ic)))
1045 bitVectUnSetBit (OP_USES (IC_COND (ic)), ic->key);
1048 /*-----------------------------------------------------------------*/
1049 /* ifxOptimize - changes ifx conditions if it can */
1050 /*-----------------------------------------------------------------*/
1052 ifxOptimize (iCode * ic, set * cseSet,
1054 eBBlock * ebb, int *change,
1055 eBBlock ** ebbs, int count)
1060 /* if the condition can be replaced */
1064 applyToSetFTrue (cseSet, findCheaperOp, IC_COND (ic), &pdop, 0);
1067 ReplaceOpWithCheaperOp(&IC_COND (ic), pdop);
1072 /* if the conditional is a literal then */
1073 if (IS_OP_LITERAL (IC_COND (ic)))
1076 if ((operandLitValue (IC_COND (ic)) != 0.0) && IC_TRUE (ic))
1079 /* change to a goto */
1081 IC_LABEL (ic) = IC_TRUE (ic);
1088 if (!operandLitValue (IC_COND (ic)) && IC_FALSE (ic))
1091 IC_LABEL (ic) = IC_FALSE (ic);
1097 /* then kill this if condition */
1098 remiCodeFromeBBlock (ebb, ic);
1102 /* now we need to recompute the control flow */
1103 /* since the control flow has changed */
1104 /* this is very expensive but it does not happen */
1105 /* too often, if it does happen then the user pays */
1107 computeControlFlow (ebbs, count, 1);
1108 if (!options.lessPedantic) {
1109 werror (W_CONTROL_FLOW, ic->filename, ic->lineno);
1114 /* if there is only one successor and that successor
1115 is the same one we are conditionally going to then
1116 we can remove this conditional statement */
1117 label = (IC_TRUE (ic) ? IC_TRUE (ic) : IC_FALSE (ic));
1118 if (elementsInSet (ebb->succList) == 1 &&
1119 isinSet (ebb->succList, eBBWithEntryLabel (ebbs, label, count)))
1122 remiCodeFromeBBlock (ebb, ic);
1123 computeControlFlow (ebbs, count, 1);
1124 if (!options.lessPedantic) {
1125 werror (W_CONTROL_FLOW, ic->filename, ic->lineno);
1131 /* if it remains an IFX the update the use Set */
1132 OP_USES(IC_COND (ic))=bitVectSetBit (OP_USES (IC_COND (ic)), ic->key);
1133 setUsesDefs (IC_COND (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs);
1137 /*-----------------------------------------------------------------*/
1138 /* diCodeForSym - finds the definiting instruction for a symbol */
1139 /*-----------------------------------------------------------------*/
1140 DEFSETFUNC (diCodeForSym)
1143 V_ARG (operand *, sym);
1144 V_ARG (iCode **, dic);
1146 /* if already found */
1150 /* if not if this is the defining iCode */
1151 if (sym->key == cdp->key)
1160 /*-----------------------------------------------------------------*/
1161 /* constFold - does some constant folding */
1162 /*-----------------------------------------------------------------*/
1164 constFold (iCode * ic, set * cseSet)
1168 /* this routine will change
1174 /* deal with only + & - */
1175 if (ic->op != '+' &&
1179 /* this check is a hueristic to prevent live ranges
1180 from becoming too long */
1181 if (IS_PTR (operandType (IC_RESULT (ic))))
1184 /* check if operation with a literal */
1185 if (!IS_OP_LITERAL (IC_RIGHT (ic)))
1188 /* check if we can find a definition for the
1190 if (!(applyToSet (cseSet, diCodeForSym, IC_LEFT (ic), &dic)))
1193 /* check that this is also a +/- */
1194 if (dic->op != '+' && dic->op != '-')
1197 /* with a literal */
1198 if (!IS_OP_LITERAL (IC_RIGHT (dic)))
1201 /* find the definition of the left operand
1202 of dic.then check if this defined with a
1203 get_pointer return 0 if the pointer size is
1204 less than 2 (MCS51 specific) */
1205 if (!(applyToSet (cseSet, diCodeForSym, IC_LEFT (dic), &ldic)))
1208 if (POINTER_GET (ldic) && getSize (operandType (IC_LEFT (ldic))) <= 1)
1211 /* it is if the operations are the same */
1212 /* the literal parts need to be added */
1213 IC_LEFT (ic) = operandFromOperand (IC_LEFT (dic));
1214 if (ic->op == dic->op)
1215 IC_RIGHT (ic) = operandFromLit (operandLitValue (IC_RIGHT (ic)) +
1216 operandLitValue (IC_RIGHT (dic)));
1218 IC_RIGHT (ic) = operandFromLit (operandLitValue (IC_RIGHT (ic)) -
1219 operandLitValue (IC_RIGHT (dic)));
1221 if (IS_ITEMP (IC_RESULT (ic)))
1223 SPIL_LOC (IC_RESULT (ic)) = NULL;
1224 OP_SYMBOL(IC_RESULT (ic))->noSpilLoc = 1;
1231 /*-----------------------------------------------------------------*/
1232 /* deleteGetPointers - called when a pointer is passed as parm */
1233 /* will delete from cseSet all get pointers computed from this */
1234 /* pointer. A simple ifOperandsHave is not good enough here */
1235 /*-----------------------------------------------------------------*/
1237 deleteGetPointers (set ** cseSet, set ** pss, operand * op, eBBlock * ebb)
1239 set *compItems = NULL;
1244 if (!*cseSet && !*pss)
1247 /* first find all items computed from this operand .
1248 This done fairly simply go thru the list and find
1249 those that are computed by arthimetic with this
1251 for (cdp = setFirstItem (*cseSet); cdp; cdp = setNextItem (*cseSet))
1253 if (IS_ARITHMETIC_OP (cdp->diCode))
1255 if (isOperandEqual (IC_LEFT (cdp->diCode), op) ||
1256 isOperandEqual (IC_RIGHT (cdp->diCode), op))
1258 /* save it in our list of items */
1259 addSet (&compItems, IC_RESULT (cdp->diCode));
1261 /* also check for those computed from our computed
1262 list . This will take care of situations like
1263 iTemp1 = iTemp0 + 8;
1264 iTemp2 = iTemp1 + 8; */
1265 if (isinSetWith (compItems, (void*)IC_LEFT (cdp->diCode),
1266 (insetwithFunc)isOperandEqual) ||
1267 isinSetWith (compItems, (void*)IC_RIGHT (cdp->diCode),
1268 (insetwithFunc)isOperandEqual))
1270 addSet (&compItems, IC_RESULT (cdp->diCode));
1275 /* now delete all pointer gets with this op */
1276 deleteItemIf (cseSet, ifPointerGet, op);
1277 deleteItemIf (pss, ifPointerSet, op);
1279 /* set the bit vector used by dataFlow computation later */
1280 ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, op->key);
1281 /* now for the computed items */
1282 for (cop = setFirstItem (compItems); cop; cop = setNextItem (compItems))
1284 ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, cop->key);
1285 deleteItemIf (cseSet, ifPointerGet, cop);
1286 deleteItemIf (pss, ifPointerSet, cop);
1290 /*-----------------------------------------------------------------*/
1291 /* delGetPointerSucc - delete get pointer from inExprs of succ with */
1292 /* dfnum > supplied */
1293 /*-----------------------------------------------------------------*/
1294 DEFSETFUNC (delGetPointerSucc)
1296 eBBlock *ebp = item;
1297 V_ARG (operand *, op);
1304 if (ebp->dfnum > dfnum)
1306 deleteItemIf (&ebp->inExprs, ifPointerGet, op);
1309 return applyToSet (ebp->succList, delGetPointerSucc, op, dfnum);
1312 /*-----------------------------------------------------------------*/
1313 /* fixUpTypes - KLUGE HACK fixup a lowering problem */
1314 /*-----------------------------------------------------------------*/
1316 fixUpTypes (iCode * ic)
1318 sym_link *t1 = operandType (IC_LEFT (ic)), *t2;
1320 /* if (TARGET_IS_DS390) */
1321 if (options.model == MODEL_FLAT24)
1327 /* for pointer_gets if the types of result & left r the
1328 same then change it type of result to next */
1330 compareType (t2 = operandType (IC_RESULT (ic)), t1) == 1)
1332 setOperandType (IC_RESULT (ic), t2->next);
1336 /*-----------------------------------------------------------------*/
1337 /* isSignedOp - will return 1 if sign is important to operation */
1338 /*-----------------------------------------------------------------*/
1339 static int isSignedOp (iCode *ic)
1360 case GET_VALUE_AT_ADDRESS:
1386 /*-----------------------------------------------------------------*/
1387 /* cseBBlock - common subexpression elimination for basic blocks */
1388 /* this is the hackiest kludgiest routine in the whole */
1389 /* system. also the most important, since almost all */
1390 /* data flow related information is computed by it */
1391 /*-----------------------------------------------------------------*/
1393 cseBBlock (eBBlock * ebb, int computeOnly,
1394 eBBlock ** ebbs, int count)
1400 set *ptrSetSet = NULL;
1402 /* if this block is not reachable */
1406 /* set of common subexpressions */
1407 cseSet = setFromSet (ebb->inExprs);
1409 /* these will be computed by this routine */
1410 setToNull ((void **) &ebb->outDefs);
1411 setToNull ((void **) &ebb->defSet);
1412 setToNull ((void **) &ebb->usesDefs);
1413 setToNull ((void **) &ebb->ptrsSet);
1414 setToNull ((void **) &ebb->addrOf);
1415 setToNull ((void **) &ebb->ldefs);
1417 ebb->outDefs = bitVectCopy (ebb->inDefs);
1418 bitVectDefault = iCodeKey;
1419 ebb->defSet = newBitVect (iCodeKey);
1420 ebb->usesDefs = newBitVect (iCodeKey);
1422 /* for all the instructions in this block do */
1423 for (ic = ebb->sch; ic; ic = ic->next)
1430 ic->eBBlockNum = ebb->bbnum;
1435 /* if this is an assignment from true symbol
1436 to a temp then do pointer post inc/dec optimzation */
1437 if (ic->op == '=' && !POINTER_SET (ic) &&
1438 IS_PTR (operandType (IC_RESULT (ic))))
1440 ptrPostIncDecOpt (ic);
1443 /* clear the def & use chains for the operands involved */
1444 /* in this operation . since it can change due to opts */
1445 unsetDefsAndUses (ic);
1447 if (ic->op == PCALL || ic->op == CALL || ic->op == RECEIVE)
1449 /* add to defSet of the symbol */
1450 OP_DEFS(IC_RESULT (ic))=
1451 bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key);
1452 /* add to the definition set of this block */
1453 ebb->defSet = bitVectSetBit (ebb->defSet, ic->key);
1454 ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key);
1455 ebb->outDefs = bitVectCplAnd (ebb->outDefs, OP_DEFS (IC_RESULT (ic)));
1456 setUsesDefs (IC_RESULT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs);
1457 /* delete global variables from the cseSet
1458 since they can be modified by the function call */
1459 deleteItemIf (&cseSet, ifDefGlobal);
1461 /* and also itemps assigned from globals */
1462 deleteItemIf (&cseSet, ifAssignedFromGlobal);
1464 /* delete all getpointer iCodes from cseSet, this should
1465 be done only for global arrays & pointers but at this
1466 point we don't know if globals, so to be safe do all */
1467 deleteItemIf (&cseSet, ifAnyGetPointer);
1470 /* for pcall & ipush we need to add to the useSet */
1471 if ((ic->op == PCALL ||
1475 IS_SYMOP (IC_LEFT (ic)))
1478 /* check if they can be replaced */
1482 applyToSetFTrue (cseSet, findCheaperOp, IC_LEFT (ic), &pdop, 0);
1484 ReplaceOpWithCheaperOp(&IC_LEFT(ic), pdop);
1486 /* the lookup could have changed it */
1487 if (IS_SYMOP (IC_LEFT (ic)))
1489 OP_USES(IC_LEFT (ic))=
1490 bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key);
1491 setUsesDefs (IC_LEFT (ic), ebb->defSet,
1492 ebb->outDefs, &ebb->usesDefs);
1496 /* if we a sending a pointer as a parameter
1497 then kill all cse since the pointed to item
1498 might be changed in the function being called */
1499 if ((ic->op == IPUSH || ic->op == SEND) &&
1500 IS_PTR (operandType (IC_LEFT (ic))))
1502 deleteGetPointers (&cseSet, &ptrSetSet, IC_LEFT (ic), ebb);
1503 ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, IC_LEFT (ic)->key);
1504 for (i = 0; i < count; ebbs[i++]->visited = 0);
1505 applyToSet (ebb->succList, delGetPointerSucc,
1506 IC_LEFT (ic), ebb->dfnum);
1511 /* if jumptable then mark the usage */
1512 if (ic->op == JUMPTABLE)
1514 OP_USES(IC_JTCOND (ic))=
1515 bitVectSetBit (OP_USES (IC_JTCOND (ic)), ic->key);
1516 setUsesDefs (IC_JTCOND (ic), ebb->defSet,
1517 ebb->outDefs, &ebb->usesDefs);
1524 /* do some algebraic optimizations if possible */
1526 while (constFold (ic, cseSet));
1529 if (POINTER_GET (ic) && !IS_PTR (operandType (IC_LEFT (ic))))
1531 setOperandType (IC_LEFT (ic),
1532 aggrToPtr (operandType (IC_LEFT (ic)), FALSE));
1536 if (POINTER_SET (ic) && !IS_PTR (operandType (IC_RESULT (ic))))
1538 setOperandType (IC_RESULT (ic),
1539 aggrToPtr (operandType (IC_RESULT (ic)), FALSE));
1542 /* if this is a condition statment then */
1543 /* check if the condition can be replaced */
1546 ifxOptimize (ic, cseSet, computeOnly,
1552 /* if the assignment & result is a temp */
1553 /* see if we can replace it */
1557 /* update the spill location for this */
1558 updateSpillLocation (ic,0);
1560 if (POINTER_SET (ic) &&
1561 !(IS_BITFIELD (OP_SYMBOL (IC_RESULT (ic))->etype)))
1564 applyToSetFTrue (cseSet, findCheaperOp, IC_RESULT (ic), &pdop, 0);
1565 if (pdop && IS_ITEMP (pdop) && !computeOnly)
1566 ReplaceOpWithCheaperOp (&IC_RESULT(ic), pdop);
1570 checkSign = isSignedOp(ic);
1572 /* do the operand lookup i.e. for both the */
1573 /* right & left operand : check the cseSet */
1574 /* to see if they have been replaced if yes */
1575 /* then replace them with those from cseSet */
1577 /* and left is a symbol */
1578 if (IS_SYMOP (IC_LEFT (ic)) &&
1579 !computeOnly && ic->op != ADDRESS_OF)
1583 applyToSetFTrue (cseSet, findCheaperOp, IC_LEFT (ic), &pdop, checkSign);
1586 if (POINTER_GET (ic))
1588 if (IS_ITEMP (pdop) || IS_OP_LITERAL (pdop))
1590 /* some non dominating block does POINTER_SET with
1591 this variable .. unsafe to remove any POINTER_GETs */
1592 if (bitVectBitValue(ebb->ndompset,IC_LEFT(ic)->key))
1593 ebb->ptrsSet = bitVectSetBit(ebb->ptrsSet,pdop->key);
1594 ReplaceOpWithCheaperOp(&IC_LEFT(ic), pdop);
1597 /* check if there is a pointer set
1598 for the same pointer visible if yes
1599 then change this into an assignment */
1601 if (applyToSetFTrue (cseSet, findPointerSet, IC_LEFT (ic), &pdop, IC_RESULT (ic)) &&
1602 !bitVectBitValue (ebb->ptrsSet, pdop->key))
1605 IC_LEFT (ic) = NULL;
1606 ReplaceOpWithCheaperOp(&IC_RIGHT(ic), pdop);
1607 SET_ISADDR (IC_RESULT (ic), 0);
1613 ReplaceOpWithCheaperOp(&IC_LEFT(ic), pdop);
1620 if (IS_SYMOP (IC_RIGHT (ic)) && !computeOnly)
1624 applyToSetFTrue (cseSet, findCheaperOp, IC_RIGHT (ic), &pdop, checkSign);
1626 ReplaceOpWithCheaperOp(&IC_RIGHT(ic), pdop);
1631 /* if left or right changed then do algebraic */
1635 while (constFold (ic, cseSet));
1638 /* if after all this it becomes a assignment to self
1639 then delete it and continue */
1640 if (ASSIGNMENT_TO_SELF (ic))
1642 remiCodeFromeBBlock (ebb, ic);
1646 /* now we will check to see if the entire */
1647 /* operation has been performed before */
1648 /* and is available */
1649 /* don't do assignments they will be killed */
1650 /* by dead code elimination if required do */
1651 /* it only if result is a temporary */
1653 if (!(POINTER_GET (ic) &&
1654 (IS_BITFIELD (OP_SYMBOL (IC_RESULT (ic))->etype) ||
1655 isOperandVolatile (IC_LEFT (ic), TRUE) ||
1656 bitVectBitValue (ebb->ndompset, IC_LEFT (ic)->key))) &&
1658 IS_ITEMP (IC_RESULT (ic)) &&
1661 applyToSet (cseSet, findPrevIc, ic, &pdic);
1662 if (pdic && compareType (operandType (IC_RESULT (pdic)),
1663 operandType (IC_RESULT (ic))) != 1)
1665 if (pdic && port->cseOk && (*port->cseOk)(ic,pdic) == 0)
1669 /* Alternate code */
1670 if (pdic && IS_ITEMP(IC_RESULT(ic))) {
1671 if (POINTER_GET(ic) && bitVectBitValue(ebb->ptrsSet,IC_LEFT(ic)->key)) {
1672 /* Mmm, found an equivalent pointer get at a lower level.
1673 This could be a loop however with the same pointer set
1676 /* if previous definition found change this to an assignment */
1679 IC_RIGHT(ic) = operandFromOperand(IC_RESULT(pdic));
1680 SET_ISADDR(IC_RESULT(ic),0);
1681 SET_ISADDR(IC_RIGHT (ic),0);
1685 if (!(POINTER_SET (ic)) && IC_RESULT (ic)) {
1686 deleteItemIf (&cseSet, ifDefSymIsX, IC_RESULT (ic));
1687 addSetHead (&cseSet, newCseDef (IC_RESULT (ic), ic));
1691 /* if assignment to a parameter which is not
1692 mine and type is a pointer then delete
1693 pointerGets to take care of aliasing */
1694 if (ASSIGNMENT (ic) &&
1695 OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic))) &&
1696 IS_PTR (operandType (IC_RESULT (ic))))
1698 deleteGetPointers (&cseSet, &ptrSetSet, IC_RIGHT (ic), ebb);
1699 for (i = 0; i < count; ebbs[i++]->visited = 0);
1700 applyToSet (ebb->succList, delGetPointerSucc, IC_RIGHT (ic), ebb->dfnum);
1701 ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, IC_RIGHT (ic)->key);
1704 /* if this is a pointerget then see if we can replace
1705 this with a previously assigned pointer value */
1706 if (POINTER_GET (ic) &&
1707 !(IS_BITFIELD (OP_SYMBOL (IC_RESULT (ic))->etype) ||
1708 isOperandVolatile (IC_LEFT (ic), TRUE)))
1711 applyToSet (ptrSetSet, findPointerSet, IC_LEFT (ic), &pdop, IC_RESULT (ic));
1712 /* if we find it then locally replace all
1713 references to the result with what we assigned */
1716 replaceAllSymBySym (ic->next, IC_RESULT (ic), pdop, &ebb->ndompset);
1720 /* delete from the cseSet anything that has */
1721 /* operands matching the result of this */
1722 /* except in case of pointer access */
1723 if (!(POINTER_SET (ic)) && IC_RESULT (ic))
1725 deleteItemIf (&cseSet, ifOperandsHave, IC_RESULT (ic));
1726 /* delete any previous definitions */
1727 ebb->defSet = bitVectCplAnd (ebb->defSet, OP_DEFS (IC_RESULT (ic)));
1731 /* add the left & right to the defUse set */
1732 if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)))
1734 OP_USES(IC_LEFT (ic))=
1735 bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key);
1736 setUsesDefs (IC_LEFT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs);
1740 if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)))
1742 OP_USES(IC_RIGHT (ic))=
1743 bitVectSetBit (OP_USES (IC_RIGHT (ic)), ic->key);
1744 setUsesDefs (IC_RIGHT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs);
1748 /* for the result it is special case, put the result */
1749 /* in the defuseSet if it a pointer or array access */
1750 if (POINTER_SET (defic))
1752 OP_USES(IC_RESULT (ic))=
1753 bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key);
1754 setUsesDefs (IC_RESULT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs);
1755 deleteItemIf (&cseSet, ifPointerGet, IC_RESULT (ic));
1756 ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, IC_RESULT (ic)->key);
1757 /* delete from inexpressions of all successors which
1758 have dfNum > than this block */
1759 for (i = 0; i < count; ebbs[i++]->visited = 0);
1760 applyToSet (ebb->succList, delGetPointerSucc, IC_RESULT (ic), ebb->dfnum);
1762 /* delete from cseSet all other pointer sets
1764 deleteItemIf (&ptrSetSet, ifPointerSet, IC_RESULT (ic));
1765 /* add to the local pointerset set */
1766 addSetHead (&ptrSetSet, newCseDef (IC_RESULT (ic), ic));
1769 /* add the result to defintion set */ if (IC_RESULT (ic))
1771 OP_DEFS(IC_RESULT (ic))=
1772 bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key);
1773 ebb->defSet = bitVectSetBit (ebb->defSet, ic->key);
1774 ebb->outDefs = bitVectCplAnd (ebb->outDefs, OP_DEFS (IC_RESULT (ic)));
1775 ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key);
1779 /* if this is an addressof instruction then */
1780 /* put the symbol in the address of list & */
1781 /* delete it from the cseSet */
1782 if (defic->op == ADDRESS_OF)
1784 addSetHead (&ebb->addrOf, IC_LEFT (ic));
1785 deleteItemIf (&cseSet, ifDefSymIsX, IC_LEFT (ic));
1789 setToNull ((void **) &ebb->outExprs);
1790 ebb->outExprs = cseSet;
1791 ebb->outDefs = bitVectUnion (ebb->outDefs, ebb->defSet);
1792 ebb->ptrsSet = bitVectUnion (ebb->ptrsSet, ebb->inPtrsSet);
1796 /*-----------------------------------------------------------------*/
1797 /* cseAllBlocks - will sequentially go thru & do cse for all blocks */
1798 /*-----------------------------------------------------------------*/
1800 cseAllBlocks (eBBlock ** ebbs, int count)
1805 /* if optimization turned off */
1807 for (i = 0; i < count; i++)
1808 change += cseBBlock (ebbs[i], FALSE, ebbs, count);