[Beignet] [PATCH] Backend: Implement the non-constant extractelement scalarize

Pan Xiuli xiuli.pan at intel.com
Wed Dec 9 21:20:48 PST 2015


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.

Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
---
 backend/src/llvm/llvm_scalarize.cpp | 44 +++++++++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 7 deletions(-)

diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp
index dc1d8ab..fed7027 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,43 @@ 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");
+        Value* foo = extr->getOperand(0);
+        Type* fooTy = foo->getType();
+
+        VectorValues& vVals = vectorVals[foo];
+        Instruction* Alloc; 
+        if(vectorAlloca.find(foo) == vectorAlloca.end())
+        {
+          Alloc = new AllocaInst(fooTy,0,"666",extr->getParent()->begin());
+        }
+        else Alloc = dyn_cast<Instruction>(vectorAlloca[foo]);
+
+        for (int i = 0; i < GetComponentCount(foo); ++i)
+        {
+          Value* foo_i = getComponent(i, foo);
+          assert(foo_i && "There are unhandled vector component");
+          Value* Idxs_i[] = {ConstantInt::get(intTy,0), ConstantInt::get(intTy,i)};
+          Instruction* writePtr = GetElementPtrInst::Create(Alloc, Idxs_i, "999", extr);
+          Instruction* Store_i = new StoreInst(foo_i,writePtr,extr);
+        }
+        Value* Idxs[] = {ConstantInt::get(intTy,0), extr->getOperand(1)};
+        Instruction* getPtr = GetElementPtrInst::Create(Alloc, Idxs, "999", extr);
+        Instruction* Loadi = new LoadInst(getPtr,"",extr);
+        extr->replaceAllUsesWith(Loadi);
+        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 +869,7 @@ namespace gbe {
     incompletePhis.clear();
     vectorVals.clear();
     usedVecVals.clear();
+    vectorAlloca.clear();
 
     delete builder;
     builder = 0;
-- 
2.1.4



More information about the Beignet mailing list