00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00064 void mark(const ShVariableNodePtr& var, int index);
00065
00066
00067 void debugDump();
00068
00069
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