00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027
#ifndef SHLINEARALLOCATOR_HPP
00028
#define SHLINEARALLOCATOR_HPP
00029
00030
#include <map>
00031
#include "ShDllExport.hpp"
00032
#include "ShVariableNode.hpp"
00033
#include "ShBackend.hpp"
00034
00035
namespace SH {
00036
00037
struct
00038
SH_DLLEXPORT ShLifeTime {
00039 ShLifeTime()
00040 {
00041 }
00042
00043 ShLifeTime(
const ShVariableNodePtr& var,
int first)
00044 : var(var), first(first), last(first)
00045 {
00046 }
00047
00048
SH::ShVariableNodePtr var;
00049
int first, last;
00050
00051
void mark(
int index)
00052 {
00053
if (first > index) first = index;
00054
if (last < index) last = index;
00055 }
00056
00057
bool operator<(
const ShLifeTime& other)
const
00058
{
00059
return first < other.first;
00060 }
00061 };
00062
00065 class
00066
SH_DLLEXPORT ShLinearAllocator {
00067
public:
00068 ShLinearAllocator(
ShBackendCodePtr backendCode);
00069
00070
00071
void mark(
const ShVariableNodePtr& var,
int index);
00072
00073
00074
void debugDump();
00075
00076
00077
void allocate();
00078
00079
private:
00080
ShBackendCodePtr m_backendCode;
00081
typedef std::map<ShVariableNodePtr, ShLifeTime> LifetimeMap;
00082 LifetimeMap m_lifetimes;
00083 };
00084
00085 };
00086
00087
#endif