ShLinearAllocator.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2006 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHLINEARALLOCATOR_HPP
00021 #define SHLINEARALLOCATOR_HPP
00022 
00023 #include <map>
00024 #include "ShDllExport.hpp"
00025 #include "ShVariableNode.hpp"
00026 #include "ShBackend.hpp"
00027 
00028 namespace SH {
00029 
00030 struct
00031 SH_DLLEXPORT ShLifeTime {
00032   ShLifeTime()
00033   {
00034   }
00035   
00036   ShLifeTime(const ShVariableNodePtr& var, int first)
00037     : var(var), first(first), last(first)
00038   {
00039   }
00040   
00041   SH::ShVariableNodePtr var;
00042   int first, last;
00043 
00044   void mark(int index)
00045   {
00046     if (first > index) first = index;
00047     if (last < index) last = index;
00048   }
00049   
00050   bool operator<(const ShLifeTime& other) const
00051   {
00052     return first < other.first;
00053   }
00054 };
00055 
00058 class
00059 SH_DLLEXPORT ShLinearAllocator {
00060 public:
00061   ShLinearAllocator(const ShBackendCodePtr& backendCode);
00062   
00063   // Mark that a variable is alive at a given index.
00064   void mark(const ShVariableNodePtr& var, int index);
00065 
00066   // Dump the life times to stderr
00067   void debugDump();
00068   
00069   // Calls back the backend with register allocation/deallocation requests.
00070   void allocate();
00071 
00072 private:
00073   ShBackendCodePtr m_backendCode;
00074   typedef std::map<ShVariableNodePtr, ShLifeTime> LifetimeMap;
00075   LifetimeMap m_lifetimes;
00076 };
00077 
00078 }
00079 
00080 #endif

Generated on Thu Feb 16 14:51:35 2006 for Sh by  doxygen 1.4.6