locations.hpp

Go to the documentation of this file.
00001 /* Copyright 1994 - 1996 LongView Technologies L.L.C. $Revision: 1.12 $ */
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 #ifdef DELTA_COMPILER
00025 
00026 // Locations manages register and stack locations. All locations are numbered. A fixed range
00027 // of indices >= 0 is assigned to arguments & registers and a growable range of indices >= 0
00028 // is assigned to stack locations.
00029 //
00030 // Note: Do not confuse Locations with the (old) class Location, which should disappear
00031 //       as soon as the new backend is up and running.
00032 
00033 class Locations: public PrintableResourceObj {
00034  private:
00035   int                   _nofArguments;          // the number of arguments
00036   int                   _nofRegisters;          // the maximum number of available registers
00037   GrowableArray<int>*   _freeList;              // the list of free locations
00038   int                   _firstFreeRegister;     // the index of the first free register in _freeList
00039   int                   _firstFreeStackTmp;     // the index of the first free stack temporary in _freeList
00040 
00041   int  argumentsBeg() const                     { return 0; }
00042   int  argumentsEnd() const                     { return _nofArguments; }
00043   int  registersBeg() const                     { return _nofArguments; }
00044   int  registersEnd() const                     { return _nofArguments + _nofRegisters; }
00045   int  stackTmpsBeg() const                     { return _nofArguments + _nofRegisters; }
00046   int  stackTmpsEnd() const                     { return _freeList->length(); }
00047   int  locationsBeg() const                     { return 0; }
00048   int  locationsEnd() const                     { return _freeList->length(); }
00049 
00050  public:
00051   enum {
00052     noLocation                  = -1,           // isLocation(noLocation) return false
00053     maxNofUsableRegisters       = 6,            // the maximum number of usable registers (<= nofRegisters)
00054     sentinel                    = 999999999     // simply much bigger than _freeList can ever get
00055   };
00056 
00057   Locations(int nofArgs, int nofRegs, int nofInitialStackTmps); // nofRegisters <= maxNofUsableRegisters
00058   Locations(Locations* l);                      // to copy locations
00059 
00060   void extendTo(int nofStackTmps);
00061 
00062   // Location management
00063   int  allocateRegister();                      // allocates a new register (fatal if !freeRegisters())
00064   int  allocateStackTmp();                      // allocates a new stack location
00065   void allocate(int i);                         // allocates location i, i must have been unallocated
00066   void use(int i);                              // uses location i once again, i must be allocated already
00067   void release(int i);                          // releases a register or stack location
00068 
00069   // Testers
00070   int  nofUses(int i) const;                    // the number of times the location has been use'd (including allocation)
00071   int  nofTotalUses() const;                    // the number of total uses of all locations (for verification purposes)
00072   int  nofArguments() const                     { return _nofArguments; }
00073   int  nofRegisters() const                     { return _nofRegisters; }
00074   int  nofStackTmps() const                     { return stackTmpsEnd() - stackTmpsBeg(); }
00075   int  nofFreeRegisters() const;                // the number of available registers
00076 
00077   bool freeRegisters() const                    { return _firstFreeRegister != sentinel; }
00078   bool isLocation(int i) const                  { return locationsBeg() <= i && i < locationsEnd(); }
00079   bool isArgument(int i) const                  { return argumentsBeg() <= i && i < argumentsEnd(); }
00080   bool isRegister(int i) const                  { return registersBeg() <= i && i < registersEnd(); }
00081   bool isStackTmp(int i) const                  { return stackTmpsBeg() <= i && i < stackTmpsEnd(); }
00082   bool isStackLoc(int i) const                  { return isArgument(i) || isStackTmp(i); }
00083 
00084   // Machine-dependent mapping of Registers/locations
00085   int  freeRegisterMask() const;                // bit i corresponds to register i; bit set <==> register is free
00086   int  usedRegisterMask() const;                // bit i corresponds to register i; bit set <==> register is used
00087 
00088   int  argumentAsLocation(int argNo) const;     // the location encoding for argument argNo
00089   int  registerAsLocation(Register reg) const;  // the location encoding for register reg
00090   int  temporaryAsLocation(int tempNo) const;   // the location encoding for temporary tempNo
00091 
00092   Register locationAsRegister  (int loc) const; // the register corresponding to loc
00093   int      locationAsRegisterNo(int loc) const  { return locationAsRegister(loc).number(); }
00094   int      locationAsWordOffset(int loc) const; // the (ebp) word offset corresponding to loc
00095   int      locationAsByteOffset(int loc) const  { return locationAsWordOffset(loc) * oopSize; }
00096   Address  locationAsAddress   (int loc) const  { return Address(ebp, locationAsByteOffset(loc)); }
00097 
00098   // Debugging
00099   void print();
00100   void verify();
00101 };
00102 
00103 #endif

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