registerMask.cpp

Go to the documentation of this file.
00001 /* Copyright 1994, LongView Technologies L.L.C. $Revision: 1.9 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 # include "incls/_precompiled.incl"
00025 
00026 # ifdef DELTA_COMPILER_unused
00027 
00028 # include "incls/_registerMask.cpp.incl"
00029 
00030 Location pick(RegisterMask& alloc, RegisterMask mask) {
00031   Unimplemented();
00032   unsigned r = mask & ~alloc;
00033   if (r == 0) return unAllocated;
00034   for (int reg = 0; ! isSet(r, 0); reg ++, r >>= 1) ;
00035   setNth(alloc, reg);
00036   // return Location(ireg, reg); /// fix this
00037   return Location();
00038 }
00039  
00040 void printAllocated(RegisterMask rs) {
00041   Unimplemented();
00042   /*
00043   printf("{");
00044   bool first = true;
00045   unsigned r = rs;              // safer for >>
00046   for (int d = 0; r; d++, r >>= 1) {
00047     if (isSet(r, 0)) {
00048       if (first) {
00049         first = false;
00050       } else {
00051         printf(",");
00052       }
00053       printf("%s", RegisterNames[d]);
00054       Unimplemented();
00055       // Location d1 = Location(d); <<< fix this
00056       Location d1;
00057       for (char c = RegisterNames[d][0];
00058            isSet(r, 1) && c == RegisterNames[d + 1][0];
00059            d ++, r >>= 1)
00060         ;
00061       if (d > d1.no()) printf("-%s", RegisterNames[d]);
00062     }
00063   }
00064   printf("}");
00065   fflush(stdout);
00066   */
00067 }
00068 
00069 
00070 inline int tempToIndex(Location temp) { Unimplemented(); return 0;
00071   // return temp - FirstStackLocation + 32;
00072 }
00073 
00074 inline Location indexToTemp(int temp) { Unimplemented(); return Location(); 
00075   // return Location(temp + FirstStackLocation - 32);
00076 }
00077 
00078 LongRegisterMask::LongRegisterMask() {
00079   bv = new BitVector(128);
00080 }
00081 
00082 void LongRegisterMask::allocate(Location l) {
00083   if (l.isRegister()) {
00084     bv->add(l.number());
00085   } else {
00086     assert(l.isStackLocation(), "should be stack reg");
00087     int i = tempToIndex(l);
00088     if (i >= bv->length) grow();
00089     bv->add(i);
00090   }
00091 }
00092 
00093 void LongRegisterMask::deallocate(Location l) {
00094   if (l.isRegister()) {
00095     bv->remove(l.number());
00096   } else {
00097     assert(l.isStackLocation(), "should be stack reg");
00098     int i = tempToIndex(l);
00099     bv->remove(i);
00100   }
00101 }
00102 
00103 bool LongRegisterMask::isAllocated(Location l) {
00104   if (l.isRegister()) {
00105     return bv->includes(l.number());
00106   } else {
00107     assert(l.isStackLocation(), "should be stack reg");
00108     int i = tempToIndex(l);
00109     if (l.number() < bv->length) {
00110       return bv->includes(i);
00111     } else {
00112       return false;
00113     }
00114   }
00115 }
00116 
00117 RegisterMask LongRegisterMask::regs() {
00118   return bv->bits[0];
00119 }
00120 
00121 void LongRegisterMask::grow() {
00122   bv = bv->copy(bv->length * 2);
00123 }
00124 
00125 void LongRegisterMask::print() {
00126 }
00127 
00128 
00129 // find the first bit >= start that is unused in all strings[0..len-1]
00130 int findFirstUnused(LongRegisterMask** masks, int len,
00131                     int start) {
00132   // currently quite unoptimized
00133   BitVector* b = masks[0]->bv->copy(masks[0]->bv->maxLength);
00134   for (int i = 1; i < len; i++) {
00135     b->unionWith(masks[i]->bv);
00136   }
00137     for (i = start; i < b->length; i++) {
00138       if (!b->includes(i)) break;
00139     }
00140   return i;
00141 }
00142 
00143 Location findFirstUnusedTemp(LongRegisterMask** masks, int len) {
00144   Unimplemented();
00145   // int i = findFirstUnused(masks, len, tempToIndex(FirstStackLocation));
00146   // return indexToTemp(i);
00147   return Location();
00148 }
00149 
00150 # endif

Generated on Mon Oct 9 13:37:26 2006 for Strongtalk VM by  doxygen 1.4.7