[Beignet] [PATCH V2] Backend: Refine new instruction with IRBuilder create

Pan Xiuli xiuli.pan at intel.com
Thu Dec 24 01:19:27 PST 2015


New instruction changes with the llvm version but the IRbuilder
is more stables. So use IRBuilder create to make it can be built
with more llvm version.

V2: Change all alloca inst to the entry of the function.
Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
---
 backend/src/llvm/llvm_scalarize.cpp | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp
index b48ff81..899a696 100644
--- a/backend/src/llvm/llvm_scalarize.cpp
+++ b/backend/src/llvm/llvm_scalarize.cpp
@@ -732,25 +732,32 @@ namespace gbe {
         Value* foo = extr->getOperand(0);
         Type* fooTy = foo->getType();
 
-        Instruction* Alloc;
+        Value* Alloc;
         if(vectorAlloca.find(foo) == vectorAlloca.end())
         {
-          Alloc = new AllocaInst(fooTy,0,"",extr->getParent()->begin());
+          BasicBlock &entry = extr->getParent()->getParent()->getEntryBlock();
+          BasicBlock::iterator bbIter = entry.begin();
+          while (isa<AllocaInst>(bbIter)) ++bbIter;
+
+          IRBuilder<> allocBuilder(&entry);
+          allocBuilder.SetInsertPoint(bbIter);
+
+          Alloc = allocBuilder.CreateAlloca(fooTy, nullptr, "");
           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);
+            Value* storePtr_i = builder->CreateGEP(Alloc, idxs_i);
+            builder->CreateStore(foo_i, storePtr_i);
           }
           vectorAlloca[foo] = Alloc;
         }
-        else Alloc = dyn_cast<Instruction>(vectorAlloca[foo]);
+        else Alloc = vectorAlloca[foo];
 
         Value* Idxs[] = {ConstantInt::get(intTy,0), extr->getOperand(1)};
-        Instruction* getPtr = GetElementPtrInst::Create(Alloc, Idxs, "", extr);
-        Instruction* loadComp = new LoadInst(getPtr,"",extr);
+        Value* getPtr = builder->CreateGEP(Alloc, Idxs);
+        Value* loadComp = builder->CreateLoad(getPtr);
         extr->replaceAllUsesWith(loadComp);
         return true;
     }
-- 
2.1.4



More information about the Beignet mailing list