nv50/ir: Rename "mkLoad" to "mkLoadv" for consistency.
[mesa.git] / src / gallium / drivers / nv50 / codegen / nv50_ir_build_util.h
index f815cf06759567fbe4fcbcc8326c7aae82dd8b90..963c3505083c3bc8e0b128b4c2aff971592352c3 100644 (file)
@@ -29,6 +29,7 @@ class BuildUtil
 {
 public:
    BuildUtil();
+   BuildUtil(Program *);
 
    inline void setProgram(Program *);
    inline Program *getProgram() const { return prog; }
@@ -45,7 +46,8 @@ public:
    inline void remove(Instruction *i) { assert(i->bb == bb); bb->remove(i); }
 
    inline LValue *getScratch(int size = 4, DataFile = FILE_GPR);
-   inline LValue *getSSA(int size = 4); // scratch value for a single assignment
+   // scratch value for a single assignment:
+   inline LValue *getSSA(int size = 4, DataFile = FILE_GPR);
 
    inline Instruction *mkOp(operation, DataType, Value *);
    Instruction *mkOp1(operation, DataType, Value *, Value *);
@@ -56,9 +58,11 @@ public:
    LValue *mkOp2v(operation, DataType, Value *, Value *, Value *);
    LValue *mkOp3v(operation, DataType, Value *, Value *, Value *, Value *);
 
-   LValue *mkLoad(DataType, Symbol *, Value *ptr);
+   Instruction *mkLoad(DataType, Value *dst, Symbol *, Value *ptr);
    Instruction *mkStore(operation, DataType, Symbol *, Value *ptr, Value *val);
 
+   LValue *mkLoadv(DataType, Symbol *, Value *ptr);
+
    Instruction *mkMov(Value *, Value *, DataType = TYPE_U32);
    Instruction *mkMovToReg(int id, Value *);
    Instruction *mkMovFromReg(Value *, int id);
@@ -75,11 +79,12 @@ public:
                       Value **def, Value **src);
    Instruction *mkQuadop(uint8_t qop, Value *, uint8_t l, Value *, Value *);
 
-   FlowInstruction *mkFlow(operation, BasicBlock *target,
-                           CondCode, Value *pred);
+   FlowInstruction *mkFlow(operation, void *target, CondCode, Value *pred);
 
    Instruction *mkSelect(Value *pred, Value *dst, Value *trSrc, Value *flSrc);
 
+   Instruction *mkSplit(Value *half[2], uint8_t halfSize, Value *);
+
    void mkClobber(DataFile file, uint32_t regMask, int regUnitLog2);
 
    ImmediateValue *mkImm(float);
@@ -94,29 +99,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 +160,6 @@ public:
 
       DataFile file;
       bool regOnly;
-
-      BuildUtil *up;
-
-      void init();
    };
 
    Symbol *mkSymbol(DataFile file, int8_t fileIndex,
@@ -138,6 +168,7 @@ public:
    Symbol *mkSysVal(SVSemantic svName, uint32_t svIndex);
 
 private:
+   void init(Program *);
    void addImmediate(ImmediateValue *);
    inline unsigned int u32Hash(uint32_t);
 
@@ -189,18 +220,16 @@ LValue *
 BuildUtil::getScratch(int size, DataFile f)
 {
    LValue *lval = new_LValue(func, f);
-   if (size != 4)
-      lval->reg.size = size;
+   lval->reg.size = size;
    return lval;
 }
 
 LValue *
-BuildUtil::getSSA(int size)
+BuildUtil::getSSA(int size, DataFile f)
 {
-   LValue *lval = new_LValue(func, FILE_GPR);
+   LValue *lval = new_LValue(func, f);
    lval->ssa = 1;
-   if (size != 4)
-      lval->reg.size = size;
+   lval->reg.size = size;
    return lval;
 }
 
@@ -255,11 +284,33 @@ BuildUtil::mkOp3v(operation op, DataType ty, Value *dst,
    return dst->asLValue();
 }
 
+inline LValue *
+BuildUtil::mkLoadv(DataType ty, Symbol *mem, Value *ptr)
+{
+   LValue *dst = getScratch();
+   mkLoad(ty, dst, mem, ptr);
+   return 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