aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/nv50/codegen/nv50_ir_build_util.h
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2012-03-27 17:30:31 +0200
committerChristoph Bumiller <[email protected]>2012-04-14 21:54:02 +0200
commit56d40aa51b34b77791cc3a49d7e86473a7459b72 (patch)
tree223c0441821522694d921cbb2d2d1f70c3f3d954 /src/gallium/drivers/nv50/codegen/nv50_ir_build_util.h
parentd41f293bf014e08df3df4324cdc02de5ce49d5ed (diff)
nv50/ir: Decouple DataArray from the dictionary that maps locations to values.
The point is to keep an independent dictionary for each function. The array that was being used as dictionary has been converted into a "bimap" for two different reasons: first, because having an almost empty instance of an array with as many entries as registers there are in the program, once for every function, would be wasteful, and second, because we want to be able to map Value pointers back to locations at some point.
Diffstat (limited to 'src/gallium/drivers/nv50/codegen/nv50_ir_build_util.h')
-rw-r--r--src/gallium/drivers/nv50/codegen/nv50_ir_build_util.h79
1 files changed, 60 insertions, 19 deletions
diff --git a/src/gallium/drivers/nv50/codegen/nv50_ir_build_util.h b/src/gallium/drivers/nv50/codegen/nv50_ir_build_util.h
index f815cf06759..69158861533 100644
--- a/src/gallium/drivers/nv50/codegen/nv50_ir_build_util.h
+++ b/src/gallium/drivers/nv50/codegen/nv50_ir_build_util.h
@@ -29,6 +29,7 @@ class BuildUtil
{
public:
BuildUtil();
+ BuildUtil(Program *);
inline void setProgram(Program *);
inline Program *getProgram() const { return prog; }
@@ -94,29 +95,58 @@ public:
Value *loadImm(Value *dst, int i) { return loadImm(dst, (uint32_t)i); }
+ struct Location
+ {
+ Location(unsigned array, unsigned arrayIdx, unsigned i, unsigned c)
+ : array(array), arrayIdx(arrayIdx), i(i), c(c) { }
+ Location(const Location &l)
+ : array(l.array), arrayIdx(l.arrayIdx), i(l.i), c(l.c) { }
+
+ bool operator==(const Location &l) const
+ {
+ return
+ array == l.array && arrayIdx == l.arrayIdx && i == l.i && c == l.c;
+ }
+
+ bool operator<(const Location &l) const
+ {
+ return array != l.array ? array < l.array :
+ arrayIdx != l.arrayIdx ? arrayIdx < l.arrayIdx :
+ i != l.i ? i < l.i :
+ c != l.c ? c < l.c :
+ false;
+ }
+
+ unsigned array, arrayIdx, i, c;
+ };
+
+ typedef bimap<Location, Value *> ValueMap;
+
class DataArray
{
public:
- DataArray();
- DataArray(BuildUtil *);
- ~DataArray();
-
- inline void setParent(BuildUtil *bld) { assert(!up); up = bld; }
+ DataArray(BuildUtil *bld) : up(bld) { }
- void setup(uint32_t base, int len, int vecDim, int size,
- DataFile, int8_t fileIndex = 0);
+ void setup(unsigned array, unsigned arrayIdx,
+ uint32_t base, int len, int vecDim, int eltSize,
+ DataFile file, int8_t fileIdx);
- inline bool exists(unsigned int i, unsigned int c);
+ inline bool exists(ValueMap&, unsigned int i, unsigned int c);
- Value *load(int i, int c, Value *ptr);
- void store(int i, int c, Value *ptr, Value *value);
- Value *acquire(int i, int c);
+ Value *load(ValueMap&, int i, int c, Value *ptr);
+ void store(ValueMap&, int i, int c, Value *ptr, Value *value);
+ Value *acquire(ValueMap&, int i, int c);
private:
- Symbol *mkSymbol(int i, int c, Symbol *base);
+ inline Value *lookup(ValueMap&, unsigned i, unsigned c);
+ inline Value *insert(ValueMap&, unsigned i, unsigned c, Value *v);
+
+ Symbol *mkSymbol(int i, int c);
private:
- Value **values;
+ BuildUtil *up;
+ unsigned array, arrayIdx;
+
uint32_t baseAddr;
uint32_t arrayLen;
Symbol *baseSym;
@@ -126,10 +156,6 @@ public:
DataFile file;
bool regOnly;
-
- BuildUtil *up;
-
- void init();
};
Symbol *mkSymbol(DataFile file, int8_t fileIndex,
@@ -138,6 +164,7 @@ public:
Symbol *mkSysVal(SVSemantic svName, uint32_t svIndex);
private:
+ void init(Program *);
void addImmediate(ImmediateValue *);
inline unsigned int u32Hash(uint32_t);
@@ -256,10 +283,24 @@ BuildUtil::mkOp3v(operation op, DataType ty, Value *dst,
}
bool
-BuildUtil::DataArray::exists(unsigned int i, unsigned int c)
+BuildUtil::DataArray::exists(ValueMap &m, unsigned int i, unsigned int c)
{
assert(i < arrayLen && c < vecDim);
- return !regOnly || values[i * vecDim + c];
+ return !regOnly || m.r.count(Location(array, arrayIdx, i, c));
+}
+
+Value *
+BuildUtil::DataArray::lookup(ValueMap &m, unsigned i, unsigned c)
+{
+ ValueMap::r_iterator it = m.r.find(Location(array, arrayIdx, i, c));
+ return it != m.r.end() ? it->second : NULL;
+}
+
+Value *
+BuildUtil::DataArray::insert(ValueMap &m, unsigned i, unsigned c, Value *v)
+{
+ m.insert(Location(array, arrayIdx, i, c), v);
+ return v;
}
} // namespace nv50_ir