diff options
author | Pan Xiuli <xiuli.pan@intel.com> | 2015-12-10 15:51:11 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2015-12-14 16:22:08 +0800 |
commit | 19fc80c432f748bd192d845ee58598352f0d898f (patch) | |
tree | e39023814dcc47ad9834c283a06f39675e1fdbc8 | |
parent | 70a0bfdcf23b311c6edd5779a839aaea708419dd (diff) |
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@intel.com>
Reviewed-by: Yang Rong <rong.r.yang@intel.com>
-rw-r--r-- | backend/src/llvm/llvm_scalarize.cpp | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp index dc1d8abb..b48ff81e 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; |