From 42d804b2a3d72a447f065b57a9f4af24bc7bef6c Mon Sep 17 00:00:00 2001 From: Tim Rowley Date: Tue, 11 Apr 2017 17:25:11 -0500 Subject: [PATCH] swr/rast: add additional jit utility functions Not used yet. Reviewed-by: Bruce Cherniak --- .../drivers/swr/rasterizer/jitter/builder.cpp | 1 + .../drivers/swr/rasterizer/jitter/builder.h | 1 + .../swr/rasterizer/jitter/builder_misc.cpp | 69 ++++++++++++++++++- .../swr/rasterizer/jitter/builder_misc.h | 6 ++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/swr/rasterizer/jitter/builder.cpp b/src/gallium/drivers/swr/rasterizer/jitter/builder.cpp index 3b86895de0b..6a33ec265fc 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/builder.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/builder.cpp @@ -47,6 +47,7 @@ namespace SwrJit mVoidTy = Type::getVoidTy(pJitMgr->mContext); mFP16Ty = Type::getHalfTy(pJitMgr->mContext); mFP32Ty = Type::getFloatTy(pJitMgr->mContext); + mFP32PtrTy = PointerType::get(mFP32Ty, 0); mDoubleTy = Type::getDoubleTy(pJitMgr->mContext); mInt1Ty = Type::getInt1Ty(pJitMgr->mContext); mInt8Ty = Type::getInt8Ty(pJitMgr->mContext); diff --git a/src/gallium/drivers/swr/rasterizer/jitter/builder.h b/src/gallium/drivers/swr/rasterizer/jitter/builder.h index 703f332fff4..8210e49b185 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/builder.h +++ b/src/gallium/drivers/swr/rasterizer/jitter/builder.h @@ -56,6 +56,7 @@ namespace SwrJit Type* mIntPtrTy; Type* mFP16Ty; Type* mFP32Ty; + Type* mFP32PtrTy; Type* mDoubleTy; Type* mInt8PtrTy; Type* mInt16PtrTy; diff --git a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp index 09b69c726df..fbb49486892 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp @@ -277,6 +277,22 @@ namespace SwrJit return GEPA(ptr, indices); } + Value *Builder::IN_BOUNDS_GEP(Value* ptr, const std::initializer_list &indexList) + { + std::vector indices; + for (auto i : indexList) + indices.push_back(i); + return IN_BOUNDS_GEP(ptr, indices); + } + + Value *Builder::IN_BOUNDS_GEP(Value* ptr, const std::initializer_list &indexList) + { + std::vector indices; + for (auto i : indexList) + indices.push_back(C(i)); + return IN_BOUNDS_GEP(ptr, indices); + } + LoadInst *Builder::LOAD(Value *basePtr, const std::initializer_list &indices, const llvm::Twine& name) { std::vector valIndices; @@ -1377,7 +1393,17 @@ namespace SwrJit IRB()->SetInsertPoint(&pFunc->getEntryBlock(), pFunc->getEntryBlock().begin()); Value* pAlloca = ALLOCA(pType); - IRB()->restoreIP(saveIP); + if (saveIP.isSet()) IRB()->restoreIP(saveIP); + return pAlloca; + } + + Value* Builder::CreateEntryAlloca(Function* pFunc, Type* pType, Value* pArraySize) + { + auto saveIP = IRB()->saveIP(); + IRB()->SetInsertPoint(&pFunc->getEntryBlock(), + pFunc->getEntryBlock().begin()); + Value* pAlloca = ALLOCA(pType, pArraySize); + if (saveIP.isSet()) IRB()->restoreIP(saveIP); return pAlloca; } @@ -1649,4 +1675,45 @@ namespace SwrJit } } + + uint32_t Builder::GetTypeSize(Type* pType) + { + if (pType->isStructTy()) + { + uint32_t numElems = pType->getStructNumElements(); + Type* pElemTy = pType->getStructElementType(0); + return numElems * GetTypeSize(pElemTy); + } + + if (pType->isArrayTy()) + { + uint32_t numElems = pType->getArrayNumElements(); + Type* pElemTy = pType->getArrayElementType(); + return numElems * GetTypeSize(pElemTy); + } + + if (pType->isIntegerTy()) + { + uint32_t bitSize = pType->getIntegerBitWidth(); + return bitSize / 8; + } + + if (pType->isFloatTy()) + { + return 4; + } + + if (pType->isHalfTy()) + { + return 2; + } + + if (pType->isDoubleTy()) + { + return 8; + } + + SWR_ASSERT(false, "Unimplemented type."); + return 0; + } } diff --git a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.h b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.h index aea39c5b777..662574d638f 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.h +++ b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.h @@ -68,6 +68,9 @@ int32_t S_IMMED(Value* i); Value *GEP(Value* ptr, const std::initializer_list &indexList); Value *GEP(Value* ptr, const std::initializer_list &indexList); +Value *IN_BOUNDS_GEP(Value* ptr, const std::initializer_list &indexList); +Value *IN_BOUNDS_GEP(Value* ptr, const std::initializer_list &indexList); + CallInst *CALL(Value *Callee, const std::initializer_list &args); CallInst *CALL(Value *Callee) { return CALLA(Callee); } CallInst *CALL(Value *Callee, Value* arg); @@ -159,8 +162,11 @@ void RDTSC_START(Value* pBucketMgr, Value* pId); void RDTSC_STOP(Value* pBucketMgr, Value* pId); Value* CreateEntryAlloca(Function* pFunc, Type* pType); +Value* CreateEntryAlloca(Function* pFunc, Type* pType, Value* pArraySize); // Static stack allocations for scatter operations Value* pScatterStackSrc{ nullptr }; Value* pScatterStackOffsets{ nullptr }; + +uint32_t GetTypeSize(Type* pType); -- 2.30.2