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

Song, Ruiling ruiling.song at intel.com
Thu Dec 24 00:54:58 PST 2015



> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Pan Xiuli
> Sent: Thursday, December 24, 2015 4:25 PM
> To: beignet at lists.freedesktop.org
> Cc: Pan, Xiuli <xiuli.pan at intel.com>
> Subject: [Beignet] [PATCH] Backend: Refine new instruction with IRBuilder
> create
> 
> 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.
> 
> Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
> ---
>  backend/src/llvm/llvm_scalarize.cpp | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/backend/src/llvm/llvm_scalarize.cpp
> b/backend/src/llvm/llvm_scalarize.cpp
> index b48ff81..0f84eea 100644
> --- a/backend/src/llvm/llvm_scalarize.cpp
> +++ b/backend/src/llvm/llvm_scalarize.cpp
> @@ -732,25 +732,25 @@ 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());
> +          Alloc = new AllocaInst(fooTy, nullptr , "", extr->getParent()->begin());
Please make sure all AllocaInst placed in a Function's entry basic block.
As we don't support dynamic stack allocation in OpenCL. Let's keep all AllocaInst in Entry block.
You can simply insert at the front of the entry block.
That would make the backend implementation simple.
And please also use IRbuilder instead of explicit AllocaInst constructor.

Thanks!
Ruiling
>            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
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list