[Beignet] [PATCH] Backend: Implement the non-constant extractelement scalarize
Yang, Rong R
rong.r.yang at intel.com
Mon Dec 14 00:17:31 PST 2015
LGTM. Pushed, thanks.
> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Pan Xiuli
> Sent: Thursday, December 10, 2015 15:51
> To: beignet at lists.freedesktop.org
> Cc: Pan, Xiuli
> Subject: [Beignet] [PATCH] Backend: Implement the non-constant
> extractelement scalarize
>
> The maybe non-constant index for the extractelement inst, it was not
> implemented in the llvm_scalarize. Now provide an implemention by
> allocating a new vector and storing all the component in it. Then can get the
> needed component by GEP inst.
>
> V2:
> Remove debuginfo and fix map insert bug
>
> Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
> ---
> backend/src/llvm/llvm_scalarize.cpp | 46
> +++++++++++++++++++++++++++++++------
> 1 file changed, 39 insertions(+), 7 deletions(-)
>
> diff --git a/backend/src/llvm/llvm_scalarize.cpp
> b/backend/src/llvm/llvm_scalarize.cpp
> index dc1d8ab..b48ff81 100644
> --- a/backend/src/llvm/llvm_scalarize.cpp
> +++ b/backend/src/llvm/llvm_scalarize.cpp
> @@ -227,6 +227,9 @@ namespace gbe {
> // of their operands hadn't before been visited (i.e. loop variant
> // variables)
> SmallVector<PHINode*, 16> incompletePhis;
> +
> + // Map for alloca vec uesd for Extractelememt < vec, alloca >
> + std::map<Value*, Value*> vectorAlloca;
> };
>
> Value* Scalarize::getComponent(int component, Value* v) @@ -723,17
> +726,45 @@ namespace gbe {
> if (! isa<Constant>(extr->getOperand(1))) {
> // TODO: Variably referenced components. Probably handle/emulate
> through
> // a series of selects.
> - NOT_IMPLEMENTED; //gla::UnsupportedFunctionality("Variably
> referenced vector components");
> + //NOT_IMPLEMENTED; //gla::UnsupportedFunctionality("Variably
> referenced vector components");
> + //TODO: This is a implement for the non-constant index, we use an
> allocated new vector
> + //to store the need vector elements.
> + Value* foo = extr->getOperand(0);
> + Type* fooTy = foo->getType();
> +
> + Instruction* Alloc;
> + if(vectorAlloca.find(foo) == vectorAlloca.end())
> + {
> + Alloc = new AllocaInst(fooTy,0,"",extr->getParent()->begin());
> + for (int i = 0; i < GetComponentCount(foo); ++i)
> + {
> + Value* foo_i = getComponent(i, foo);
> + assert(foo_i && "There is unhandled vector component");
> + Value* idxs_i[] = {ConstantInt::get(intTy,0), ConstantInt::get(intTy,i)};
> + Instruction* storePtr_i = GetElementPtrInst::Create(Alloc, idxs_i, "",
> extr);
> + new StoreInst(foo_i, storePtr_i, extr);
> + }
> + vectorAlloca[foo] = Alloc;
> + }
> + else Alloc = dyn_cast<Instruction>(vectorAlloca[foo]);
> +
> + Value* Idxs[] = {ConstantInt::get(intTy,0), extr->getOperand(1)};
> + Instruction* getPtr = GetElementPtrInst::Create(Alloc, Idxs, "", extr);
> + Instruction* loadComp = new LoadInst(getPtr,"",extr);
> + extr->replaceAllUsesWith(loadComp);
> + return true;
> }
> //if (isa<Argument>(extr->getOperand(0)))
> // return false;
> - int component = GetConstantInt(extr->getOperand(1));
> - Value* v = getComponent(component, extr->getOperand(0));
> - if(extr == v)
> - return false;
> - replaceAllUsesOfWith(dyn_cast<Instruction>(extr),
> dyn_cast<Instruction>(v));
> + else{
> + int component = GetConstantInt(extr->getOperand(1));
> + Value* v = getComponent(component, extr->getOperand(0));
> + if(extr == v)
> + return false;
> + replaceAllUsesOfWith(dyn_cast<Instruction>(extr),
> + dyn_cast<Instruction>(v));
>
> - return true;
> + return true;
> + }
> }
>
> bool Scalarize::scalarizeInsert(InsertElementInst* ins) @@ -840,6 +871,7
> @@ namespace gbe {
> incompletePhis.clear();
> vectorVals.clear();
> usedVecVals.clear();
> + vectorAlloca.clear();
>
> delete builder;
> builder = 0;
> --
> 2.1.4
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list