swr/rast: add additional jit utility functions
authorTim Rowley <timothy.o.rowley@intel.com>
Tue, 11 Apr 2017 22:25:11 +0000 (17:25 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Sat, 29 Apr 2017 00:55:02 +0000 (19:55 -0500)
Not used yet.

Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/jitter/builder.cpp
src/gallium/drivers/swr/rasterizer/jitter/builder.h
src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp
src/gallium/drivers/swr/rasterizer/jitter/builder_misc.h

index 3b86895de0b5ba6b631268e9e5293dcc8e50750a..6a33ec265fc90878216f036e2ff9ac6436d64ff2 100644 (file)
@@ -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);
index 703f332fff4141e117e97086eb1d29962f7c3bcc..8210e49b18527f422b6f376f9597384f396a6ebd 100644 (file)
@@ -56,6 +56,7 @@ namespace SwrJit
         Type*                mIntPtrTy;
         Type*                mFP16Ty;
         Type*                mFP32Ty;
+        Type*                mFP32PtrTy;
         Type*                mDoubleTy;
         Type*                mInt8PtrTy;
         Type*                mInt16PtrTy;
index 09b69c726df1b2482f63a51523bddc6f070f5af4..fbb49486892801adcd5685b6cb48c2d70ee12d3c 100644 (file)
@@ -277,6 +277,22 @@ namespace SwrJit
         return GEPA(ptr, indices);
     }
 
+    Value *Builder::IN_BOUNDS_GEP(Value* ptr, const std::initializer_list<Value*> &indexList)
+    {
+        std::vector<Value*> 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<uint32_t> &indexList)
+    {
+        std::vector<Value*> 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<uint32_t> &indices, const llvm::Twine& name)
     {
         std::vector<Value*> 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;
+    }
 }
index aea39c5b777e118d4c2e8f9a5a716be022bf8934..662574d638f9aa3ec4c33674d25a1e28318a64af 100644 (file)
@@ -68,6 +68,9 @@ int32_t S_IMMED(Value* i);
 
 Value *GEP(Value* ptr, const std::initializer_list<Value*> &indexList);
 Value *GEP(Value* ptr, const std::initializer_list<uint32_t> &indexList);
+Value *IN_BOUNDS_GEP(Value* ptr, const std::initializer_list<Value*> &indexList);
+Value *IN_BOUNDS_GEP(Value* ptr, const std::initializer_list<uint32_t> &indexList);
+
 CallInst *CALL(Value *Callee, const std::initializer_list<Value*> &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);