diff options
author | Zack Rusin <[email protected]> | 2008-02-15 00:36:18 -0500 |
---|---|---|
committer | Zack Rusin <[email protected]> | 2008-02-15 01:17:17 -0500 |
commit | 4593be34b2a6e494f0e476c8aa8e1d2633fffd47 (patch) | |
tree | 485a79634e70fe0a0f1300241ee257bb8ec75946 /src/mesa | |
parent | cf51d5c4210d3301c96947e6e80e71c252bc04d1 (diff) |
vastly simplify indexing
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/pipe/llvm/instructionssoa.cpp | 14 | ||||
-rw-r--r-- | src/mesa/pipe/llvm/storagesoa.cpp | 156 | ||||
-rw-r--r-- | src/mesa/pipe/llvm/storagesoa.h | 18 | ||||
-rw-r--r-- | src/mesa/pipe/llvm/tgsitollvm.cpp | 1 |
4 files changed, 59 insertions, 130 deletions
diff --git a/src/mesa/pipe/llvm/instructionssoa.cpp b/src/mesa/pipe/llvm/instructionssoa.cpp index 9c38c64bd10..a4d50466373 100644 --- a/src/mesa/pipe/llvm/instructionssoa.cpp +++ b/src/mesa/pipe/llvm/instructionssoa.cpp @@ -47,22 +47,10 @@ std::vector<llvm::Value*> InstructionsSoa::arl(const std::vector<llvm::Value*> i llvm::Value *x1 = m_builder.CreateExtractElement(in[0], m_storage->constantInt(0), name("extractX")); - llvm::Value *x2 = m_builder.CreateExtractElement(in[0], - m_storage->constantInt(1), - name("extractX")); - llvm::Value *x3 = m_builder.CreateExtractElement(in[0], - m_storage->constantInt(2), - name("extractX")); - llvm::Value *x4 = m_builder.CreateExtractElement(in[0], - m_storage->constantInt(3), - name("extractX")); //cast it to an unsigned int x1 = m_builder.CreateFPToUI(x1, IntegerType::get(32), name("x1IntCast")); - x2 = m_builder.CreateFPToUI(x2, IntegerType::get(32), name("x2IntCast")); - x3 = m_builder.CreateFPToUI(x3, IntegerType::get(32), name("x3IntCast")); - x4 = m_builder.CreateFPToUI(x4, IntegerType::get(32), name("x4IntCast")); - res[0] = vectorFromVals(x1, x2, x3, x4); + res[0] = x1;//vectorFromVals(x1, x2, x3, x4); //only x is valid. the others shouldn't be necessary /* res[1] = Constant::getNullValue(m_floatVecType); diff --git a/src/mesa/pipe/llvm/storagesoa.cpp b/src/mesa/pipe/llvm/storagesoa.cpp index 314ffe62dc3..ed0674a96f0 100644 --- a/src/mesa/pipe/llvm/storagesoa.cpp +++ b/src/mesa/pipe/llvm/storagesoa.cpp @@ -132,40 +132,27 @@ llvm::Value *StorageSoa::addrElement(int idx) const return res; } -std::vector<llvm::Value*> StorageSoa::inputElement(int idx, llvm::Value *indIdx) +std::vector<llvm::Value*> StorageSoa::inputElement(llvm::Value *idx) { std::vector<llvm::Value*> res(4); - if (!indIdx) { - res[0] = element(m_input, idx, 0); - res[1] = element(m_input, idx, 1); - res[2] = element(m_input, idx, 2); - res[3] = element(m_input, idx, 3); - } else { - res[0] = indirectElement(m_input, indIdx, 0); - res[1] = indirectElement(m_input, indIdx, 1); - res[2] = indirectElement(m_input, indIdx, 2); - res[3] = indirectElement(m_input, indIdx, 3); - } + res[0] = element(m_input, idx, 0); + res[1] = element(m_input, idx, 1); + res[2] = element(m_input, idx, 2); + res[3] = element(m_input, idx, 3); return res; } -std::vector<llvm::Value*> StorageSoa::constElement(int idx, llvm::Value *indIdx) +std::vector<llvm::Value*> StorageSoa::constElement(llvm::Value *idx) { std::vector<llvm::Value*> res(4); llvm::Value *xChannel, *yChannel, *zChannel, *wChannel; - if (!indIdx) { - xChannel = elementPointer(m_consts, idx, 0); - yChannel = elementPointer(m_consts, idx, 1); - zChannel = elementPointer(m_consts, idx, 2); - wChannel = elementPointer(m_consts, idx, 3); - } else { - xChannel = indirectElementPointer(m_consts, indIdx, 0); - yChannel = indirectElementPointer(m_consts, indIdx, 1); - zChannel = indirectElementPointer(m_consts, indIdx, 2); - wChannel = indirectElementPointer(m_consts, indIdx, 3); - } + + xChannel = elementPointer(m_consts, idx, 0); + yChannel = elementPointer(m_consts, idx, 1); + zChannel = elementPointer(m_consts, idx, 2); + wChannel = elementPointer(m_consts, idx, 3); res[0] = alignedArrayLoad(xChannel); res[1] = alignedArrayLoad(yChannel); @@ -175,70 +162,49 @@ std::vector<llvm::Value*> StorageSoa::constElement(int idx, llvm::Value *indIdx) return res; } -std::vector<llvm::Value*> StorageSoa::outputElement(int idx, llvm::Value *indIdx) +std::vector<llvm::Value*> StorageSoa::outputElement(llvm::Value *idx) { std::vector<llvm::Value*> res(4); - if (!indIdx) { - res[0] = element(m_output, idx, 0); - res[1] = element(m_output, idx, 1); - res[2] = element(m_output, idx, 2); - res[3] = element(m_output, idx, 3); - } else { - res[0] = indirectElement(m_output, indIdx, 0); - res[1] = indirectElement(m_output, indIdx, 1); - res[2] = indirectElement(m_output, indIdx, 2); - res[3] = indirectElement(m_output, indIdx, 3); - } + res[0] = element(m_output, idx, 0); + res[1] = element(m_output, idx, 1); + res[2] = element(m_output, idx, 2); + res[3] = element(m_output, idx, 3); return res; } -std::vector<llvm::Value*> StorageSoa::tempElement(int idx, llvm::Value *indIdx) +std::vector<llvm::Value*> StorageSoa::tempElement(llvm::Value *idx) { std::vector<llvm::Value*> res(4); - if (!indIdx) { - res[0] = element(m_temps, idx, 0); - res[1] = element(m_temps, idx, 1); - res[2] = element(m_temps, idx, 2); - res[3] = element(m_temps, idx, 3); - } else { - res[0] = indirectElement(m_temps, indIdx, 0); - res[1] = indirectElement(m_temps, indIdx, 1); - res[2] = indirectElement(m_temps, indIdx, 2); - res[3] = indirectElement(m_temps, indIdx, 3); - } + res[0] = element(m_temps, idx, 0); + res[1] = element(m_temps, idx, 1); + res[2] = element(m_temps, idx, 2); + res[3] = element(m_temps, idx, 3); return res; } -std::vector<llvm::Value*> StorageSoa::immediateElement(int idx, llvm::Value *indIdx) +std::vector<llvm::Value*> StorageSoa::immediateElement(llvm::Value *idx) { std::vector<llvm::Value*> res(4); - if (!indIdx) { - res[0] = element(m_immediates, idx, 0); - res[1] = element(m_immediates, idx, 1); - res[2] = element(m_immediates, idx, 2); - res[3] = element(m_immediates, idx, 3); - } else { - res[0] = indirectElement(m_immediates, indIdx, 0); - res[1] = indirectElement(m_immediates, indIdx, 1); - res[2] = indirectElement(m_immediates, indIdx, 2); - res[3] = indirectElement(m_immediates, indIdx, 3); - } + res[0] = element(m_immediates, idx, 0); + res[1] = element(m_immediates, idx, 1); + res[2] = element(m_immediates, idx, 2); + res[3] = element(m_immediates, idx, 3); return res; } -llvm::Value * StorageSoa::elementPointer(llvm::Value *ptr, int index, +llvm::Value * StorageSoa::elementPointer(llvm::Value *ptr, llvm::Value *index, int channel) const { std::vector<Value*> indices; if (m_immediates == ptr) indices.push_back(constantInt(0)); - indices.push_back(constantInt(index)); + indices.push_back(index); indices.push_back(constantInt(channel)); GetElementPtrInst *getElem = new GetElementPtrInst(ptr, @@ -249,7 +215,7 @@ llvm::Value * StorageSoa::elementPointer(llvm::Value *ptr, int index, return getElem; } -llvm::Value * StorageSoa::element(llvm::Value *ptr, int index, +llvm::Value * StorageSoa::element(llvm::Value *ptr, llvm::Value *index, int channel) const { llvm::Value *res = elementPointer(ptr, index, channel); @@ -315,23 +281,31 @@ std::vector<llvm::Value*> StorageSoa::load(Argument type, int idx, int swizzle, llvm::Value *indIdx) { std::vector<llvm::Value*> val(4); - debug_printf("XXXXXXXXX indIdx = %p\n", indIdx); - assert(!indIdx); + + //if we have an indirect index, always use that + // if not use the integer offset to create one + llvm::Value *realIndex = 0; + if (indIdx) + realIndex = indIdx; + else + realIndex = constantInt(idx); + debug_printf("XXXXXXXXX realIdx = %p, indIdx = %p\n", realIndex, indIdx); + switch(type) { case Input: - val = inputElement(idx, indIdx); + val = inputElement(realIndex); break; case Output: - val = outputElement(idx, indIdx); + val = outputElement(realIndex); break; case Temp: - val = tempElement(idx, indIdx); + val = tempElement(realIndex); break; case Const: - val = constElement(idx, indIdx); + val = constElement(realIndex); break; case Immediate: - val = immediateElement(idx, indIdx); + val = immediateElement(realIndex); break; case Address: debug_printf("Address not handled in the load phase!\n"); @@ -380,64 +354,36 @@ void StorageSoa::store(Argument type, int idx, const std::vector<llvm::Value*> & assert(0); break; } - + llvm::Value *realIndex = constantInt(idx); if ((mask & TGSI_WRITEMASK_X)) { - llvm::Value *xChannel = elementPointer(out, idx, 0); + llvm::Value *xChannel = elementPointer(out, realIndex, 0); new StoreInst(val[0], xChannel, false, m_block); } if ((mask & TGSI_WRITEMASK_Y)) { - llvm::Value *yChannel = elementPointer(out, idx, 1); + llvm::Value *yChannel = elementPointer(out, realIndex, 1); new StoreInst(val[1], yChannel, false, m_block); } if ((mask & TGSI_WRITEMASK_Z)) { - llvm::Value *zChannel = elementPointer(out, idx, 2); + llvm::Value *zChannel = elementPointer(out, realIndex, 2); new StoreInst(val[2], zChannel, false, m_block); } if ((mask & TGSI_WRITEMASK_W)) { - llvm::Value *wChannel = elementPointer(out, idx, 3); + llvm::Value *wChannel = elementPointer(out, realIndex, 3); new StoreInst(val[3], wChannel, false, m_block); } } void StorageSoa::addAddress(int idx) { - VectorType *vectorType = VectorType::get(Type::FloatTy, 4); GlobalVariable *val = new GlobalVariable( - /*Type=*/vectorType, + /*Type=*/IntegerType::get(32), /*isConstant=*/false, /*Linkage=*/GlobalValue::ExternalLinkage, /*Initializer=*/0, // has initializer, specified below /*Name=*/name("address"), currentModule()); - //val->setInitializer(Constant::getNullValue(IntegerType::get(32))); - //val->setInitializer(constantInt(1)); + val->setInitializer(Constant::getNullValue(IntegerType::get(32))); debug_printf("adding to %d\n", idx); m_addresses[idx] = val; } - -llvm::Value * StorageSoa::indirectElementPointer(llvm::Value *ptr, llvm::Value *indIdx, - int channel) const -{ - std::vector<Value*> indices; - if (m_immediates == ptr) - indices.push_back(constantInt(0)); - indices.push_back(indIdx); - indices.push_back(constantInt(channel)); - - GetElementPtrInst *getElem = new GetElementPtrInst(ptr, - indices.begin(), - indices.end(), - name("ptr"), - m_block); - return getElem; -} - -llvm::Value * StorageSoa::indirectElement(llvm::Value *ptr, llvm::Value *indIdx, - int channel) const -{ - llvm::Value *res = indirectElementPointer(ptr, indIdx, channel); - LoadInst *load = new LoadInst(res, name("element"), false, m_block); - //load->setAlignment(8); - return load; -} diff --git a/src/mesa/pipe/llvm/storagesoa.h b/src/mesa/pipe/llvm/storagesoa.h index ca8fee63407..6443351f270 100644 --- a/src/mesa/pipe/llvm/storagesoa.h +++ b/src/mesa/pipe/llvm/storagesoa.h @@ -76,24 +76,20 @@ public: llvm::ConstantInt *constantInt(int) const; private: - llvm::Value *elementPointer(llvm::Value *ptr, int index, + llvm::Value *elementPointer(llvm::Value *ptr, llvm::Value *indIdx, int channel) const; - llvm::Value *element(llvm::Value *ptr, int index, + llvm::Value *element(llvm::Value *ptr, llvm::Value *idx, int channel) const; - llvm::Value *indirectElementPointer(llvm::Value *ptr, llvm::Value *indIdx, - int channel) const; - llvm::Value *indirectElement(llvm::Value *ptr, llvm::Value *indIdx, - int channel) const; const char *name(const char *prefix) const; llvm::Value *alignedArrayLoad(llvm::Value *val); llvm::Module *currentModule() const; llvm::Constant *createConstGlobalVector(const std::vector<float> &vec); - std::vector<llvm::Value*> inputElement(int idx, llvm::Value *indIdx =0); - std::vector<llvm::Value*> constElement(int idx, llvm::Value *indIdx =0); - std::vector<llvm::Value*> outputElement(int idx, llvm::Value *indIdx =0); - std::vector<llvm::Value*> tempElement(int idx, llvm::Value *indIdx =0); - std::vector<llvm::Value*> immediateElement(int idx, llvm::Value *indIdx =0); + std::vector<llvm::Value*> inputElement(llvm::Value *indIdx); + std::vector<llvm::Value*> constElement(llvm::Value *indIdx); + std::vector<llvm::Value*> outputElement(llvm::Value *indIdx); + std::vector<llvm::Value*> tempElement(llvm::Value *indIdx); + std::vector<llvm::Value*> immediateElement(llvm::Value *indIdx); private: llvm::BasicBlock *m_block; diff --git a/src/mesa/pipe/llvm/tgsitollvm.cpp b/src/mesa/pipe/llvm/tgsitollvm.cpp index 071b7d112e4..0de595e6789 100644 --- a/src/mesa/pipe/llvm/tgsitollvm.cpp +++ b/src/mesa/pipe/llvm/tgsitollvm.cpp @@ -707,7 +707,6 @@ translate_instructionir(llvm::Module *module, if (src->SrcRegister.Indirect) { indIdx = storage->addrElement(src->SrcRegisterInd.Index); - debug_printf("AAAAAAAAAAAAAAA INDIRECT %p\n", indIdx); } if (src->SrcRegister.File == TGSI_FILE_CONSTANT) { val = storage->load(StorageSoa::Const, |