+/*-----------------------------------------------------------------*/
+/* computeClash - find out which live ranges collide with others */
+/*-----------------------------------------------------------------*/
+static void computeClash ()
+{
+ hTab *lRangeCopy = newHashTable(hTabMaxKey(liveRanges));
+ void *item;
+ symbol *outer, *inner;
+ int key, key1;
+
+ /* have to make a copy of the liveRanges hashTable :: UGHH .*/
+ for (item = hTabFirstItem(liveRanges,&key); item ;
+ item = hTabNextItem(liveRanges,&key)) {
+ hTabAddItem(&lRangeCopy,key,item);
+ }
+
+ /* outerloop : for each liverange do */
+ for (outer = hTabFirstItem(liveRanges,&key); outer ;
+ outer = hTabNextItem(liveRanges,&key)) {
+
+ /* if the liveFrom & To are the same then skip,
+ could happen for unused return values from functions */
+ if (outer->liveFrom == outer->liveTo) continue;
+
+ /* innerloop : for the inner loop we can start from the
+ item after the outer loop */
+ inner = hTabFirstItemWK (lRangeCopy,outer->key);
+ inner = hTabNextItem (lRangeCopy,&key1 );
+ for (; inner ; inner = hTabNextItem( lRangeCopy ,&key1)) {
+
+ if (inner->liveFrom == inner->liveTo) continue;
+ if (inner->liveTo < outer->liveFrom) continue;
+ if (inner->liveFrom > outer->liveTo) continue;
+
+ /* if one of them are being defined where the other
+ one end , then no overlap (i.e. they can goto same registers */
+ if (inner->liveFrom == outer->liveTo ||
+ outer->liveFrom == inner->liveTo) continue;
+
+ /* so they overlap : set both their clashes */
+ inner->clashes = bitVectSetBit(inner->clashes,outer->key);
+ outer->clashes = bitVectSetBit(outer->clashes,inner->key);
+
+ /* check if they share the same spillocation */
+ if (SYM_SPIL_LOC(inner) && SYM_SPIL_LOC(outer)) {
+ if (inner->reqv && !outer->reqv) SYM_SPIL_LOC(outer)=NULL;
+ else if (outer->reqv && !inner->reqv) SYM_SPIL_LOC(inner)=NULL;
+ else if (inner->used > outer->used) SYM_SPIL_LOC(outer)=NULL;
+ else SYM_SPIL_LOC(inner)=NULL;
+ }
+ }
+ }
+}