Mesa (master): swr: Fix building with LLVM12

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 16 09:21:46 UTC 2020


Module: Mesa
Branch: master
Commit: 87d7568d69199d1fa16858b45521764d31815aa9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=87d7568d69199d1fa16858b45521764d31815aa9

Author: jzielins <jan.zielinski at intel.com>
Date:   Thu Dec 10 17:55:35 2020 +0100

swr: Fix building with LLVM12

Updates SWR code to match recent changes
in StructType and VectorType APIs

Fixes: #3917

Reviewed-by: Krzysztof Raszkowski <krzysztof.raszkowski at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8041>

---

 .../rasterizer/codegen/templates/gen_builder.hpp   |  4 ++-
 .../swr/rasterizer/codegen/templates/gen_llvm.hpp  |  6 ++++
 .../drivers/swr/rasterizer/jitter/JitManager.cpp   |  6 ++++
 .../drivers/swr/rasterizer/jitter/builder_misc.cpp | 16 +++++++--
 .../rasterizer/jitter/functionpasses/lower_x86.cpp | 41 +++++++++++++++++-----
 5 files changed, 62 insertions(+), 11 deletions(-)

diff --git a/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_builder.hpp b/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_builder.hpp
index d7858873ece..da1ca87620a 100644
--- a/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_builder.hpp
+++ b/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_builder.hpp
@@ -46,7 +46,9 @@ ${func['decl']}
     %for arg in func['args']:
     argTypes.push_back(${arg}->getType());
     %endfor
-#if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+    #define VEC_GET_NUM_ELEMS cast<FixedVectorType>(a->getType())->getNumElements()
+#elif LLVM_VERSION_MAJOR >= 11
     #define VEC_GET_NUM_ELEMS cast<VectorType>(a->getType())->getNumElements()
 #else
     #define VEC_GET_NUM_ELEMS a->getType()->getVectorNumElements()
diff --git a/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_llvm.hpp b/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_llvm.hpp
index df2934fa615..99a3f300bba 100644
--- a/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_llvm.hpp
+++ b/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_llvm.hpp
@@ -32,6 +32,8 @@
  ******************************************************************************/
 // clang-format off
 
+#include <llvm/IR/DerivedTypes.h>
+
 #pragma once
 
 namespace SwrJit
@@ -45,7 +47,11 @@ namespace SwrJit
         LLVMContext& ctx = pJitMgr->mContext;
 
         %endif
+#if LLVM_VERSION_MAJOR >= 12
+        StructType* pRetType = StructType::getTypeByName(pJitMgr->mContext, "${type['name']}");
+#else
         StructType* pRetType = pJitMgr->mpCurrentModule->getTypeByName("${type['name']}");
+#endif
         if (pRetType == nullptr)
         {
             std::vector<Type*> members =<% (max_type_len, max_name_len) = calc_max_len(type['members']) %>
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
index 7b8689933b5..44482939c76 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
+++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
@@ -381,7 +381,13 @@ DIType* JitManager::GetDebugIntegerType(Type* pTy)
 DIType* JitManager::GetDebugVectorType(Type* pTy)
 {
     DIBuilder                 builder(*mpCurrentModule);
+#if LLVM_VERSION_MAJOR >= 12
+    FixedVectorType*          pVecTy    = cast<FixedVectorType>(pTy);
+#elif LLVM_VERSION_MAJOR >= 11
     VectorType*               pVecTy    = cast<VectorType>(pTy);
+#else
+    auto                      pVecTy    = pTy;
+#endif
     DataLayout                DL        = DataLayout(mpCurrentModule);
     uint32_t                  size      = DL.getTypeAllocSizeInBits(pVecTy);
     uint32_t                  alignment = DL.getABITypeAlignment(pVecTy);
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp
index fc5d782a55c..f30db9a3834 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp
+++ b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp
@@ -392,7 +392,9 @@ namespace SwrJit
             if (pType->isVectorTy())
             {
                 Type* pContainedType = pType->getContainedType(0);
-#if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+                FixedVectorType* pVectorType = cast<FixedVectorType>(pType);
+#elif LLVM_VERSION_MAJOR >= 11
                 VectorType* pVectorType = cast<VectorType>(pType);
 #endif
                 if (toupper(tempStr[pos + 1]) == 'X')
@@ -575,7 +577,11 @@ namespace SwrJit
     Value* Builder::VMOVMSK(Value* mask)
     {
 #if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+        FixedVectorType* pVectorType = cast<FixedVectorType>(mask->getType());
+#else
         VectorType* pVectorType = cast<VectorType>(mask->getType());
+#endif
         SWR_ASSERT(pVectorType->getElementType() == mInt1Ty);
         uint32_t numLanes = pVectorType->getNumElements();
 #else
@@ -620,7 +626,11 @@ namespace SwrJit
             Constant* cB = dyn_cast<Constant>(b);
             assert(cB != nullptr);
             // number of 8 bit elements in b
+#if LLVM_VERSION_MAJOR >= 12
+            uint32_t numElms = cast<FixedVectorType>(cB->getType())->getNumElements();
+#else
             uint32_t numElms = cast<VectorType>(cB->getType())->getNumElements();
+#endif
             // output vector
             Value* vShuf = UndefValue::get(getVectorType(mInt8Ty, numElms));
 
@@ -687,7 +697,9 @@ namespace SwrJit
     Value* Builder::CVTPH2PS(Value* a, const llvm::Twine& name)
     {
         // Bitcast Nxint16 to Nxhalf
-#if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+        uint32_t numElems = cast<FixedVectorType>(a->getType())->getNumElements();
+#elif LLVM_VERSION_MAJOR >= 11
         uint32_t numElems = cast<VectorType>(a->getType())->getNumElements();
 #else
         uint32_t numElems = a->getType()->getVectorNumElements();
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/functionpasses/lower_x86.cpp b/src/gallium/drivers/swr/rasterizer/jitter/functionpasses/lower_x86.cpp
index 7ee22899c12..e5fb08b5e56 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/functionpasses/lower_x86.cpp
+++ b/src/gallium/drivers/swr/rasterizer/jitter/functionpasses/lower_x86.cpp
@@ -173,7 +173,9 @@ namespace SwrJit
 
     static uint32_t getBitWidth(VectorType *pVTy)
     {
-#if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+        return cast<FixedVectorType>(pVTy)->getNumElements() * pVTy->getElementType()->getPrimitiveSizeInBits();
+#elif LLVM_VERSION_MAJOR >= 11
         return pVTy->getNumElements() * pVTy->getElementType()->getPrimitiveSizeInBits();
 #else
         return pVTy->getBitWidth();
@@ -320,7 +322,9 @@ namespace SwrJit
         // Convert <N x i1> mask to <N x i32> x86 mask
         Value* VectorMask(Value* vi1Mask)
         {
-#if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+            uint32_t numElem = cast<FixedVectorType>(vi1Mask->getType())->getNumElements();
+#elif LLVM_VERSION_MAJOR >= 11
             uint32_t numElem = cast<VectorType>(vi1Mask->getType())->getNumElements();
 #else
             uint32_t numElem = vi1Mask->getType()->getVectorNumElements();
@@ -509,7 +513,9 @@ namespace SwrJit
         else
         {
             v32Result = UndefValue::get(v32A->getType());
-#if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+            uint32_t numElem = cast<FixedVectorType>(v32A->getType())->getNumElements();
+#elif LLVM_VERSION_MAJOR >= 11
             uint32_t numElem = cast<VectorType>(v32A->getType())->getNumElements();
 #else
             uint32_t numElem = v32A->getType()->getVectorNumElements();
@@ -536,7 +542,11 @@ namespace SwrJit
 
         pBase              = B->POINTER_CAST(pBase, PointerType::get(B->mInt8Ty, 0));
 #if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+        FixedVectorType* pVectorType = cast<FixedVectorType>(vSrc->getType());
+#else
         VectorType* pVectorType = cast<VectorType>(vSrc->getType());
+#endif
         uint32_t    numElem     = pVectorType->getNumElements();
         auto        srcTy       = pVectorType->getElementType();
 #else
@@ -609,14 +619,18 @@ namespace SwrJit
             else if (width == W512)
             {
                 // Double pump 4-wide for 64bit elements
-#if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+                if (cast<FixedVectorType>(vSrc->getType())->getElementType() == B->mDoubleTy)
+#elif LLVM_VERSION_MAJOR >= 11
                 if (cast<VectorType>(vSrc->getType())->getElementType() == B->mDoubleTy)
 #else
                 if (vSrc->getType()->getVectorElementType() == B->mDoubleTy)
 #endif
                 {
                     auto v64Mask = pThis->VectorMask(vi1Mask);
-#if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+                    uint32_t numElem = cast<FixedVectorType>(v64Mask->getType())->getNumElements();
+#elif LLVM_VERSION_MAJOR >= 11
                     uint32_t numElem = cast<VectorType>(v64Mask->getType())->getNumElements();
 #else
                     uint32_t numElem = v64Mask->getType()->getVectorNumElements();
@@ -633,7 +647,12 @@ namespace SwrJit
                     Value* mask0 = B->VSHUFFLE(v64Mask, v64Mask, B->C({0, 1, 2, 3}));
                     Value* mask1 = B->VSHUFFLE(v64Mask, v64Mask, B->C({4, 5, 6, 7}));
 
-#if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+                    uint32_t numElemSrc0  = cast<FixedVectorType>(src0->getType())->getNumElements();
+                    uint32_t numElemMask0 = cast<FixedVectorType>(mask0->getType())->getNumElements();
+                    uint32_t numElemSrc1  = cast<FixedVectorType>(src1->getType())->getNumElements();
+                    uint32_t numElemMask1 = cast<FixedVectorType>(mask1->getType())->getNumElements();
+#elif LLVM_VERSION_MAJOR >= 11
                     uint32_t numElemSrc0  = cast<VectorType>(src0->getType())->getNumElements();
                     uint32_t numElemMask0 = cast<VectorType>(mask0->getType())->getNumElements();
                     uint32_t numElemSrc1  = cast<VectorType>(src1->getType())->getNumElements();
@@ -891,7 +910,10 @@ namespace SwrJit
                 auto argType = arg.get()->getType();
                 if (argType->isVectorTy())
                 {
-#if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+                    uint32_t vecWidth  = cast<FixedVectorType>(argType)->getNumElements();
+                    auto     elemTy    = cast<FixedVectorType>(argType)->getElementType();
+#elif LLVM_VERSION_MAJOR >= 11
                     uint32_t vecWidth  = cast<VectorType>(argType)->getNumElements();
                     auto     elemTy    = cast<VectorType>(argType)->getElementType();
 #else
@@ -913,7 +935,10 @@ namespace SwrJit
         if (result[0]->getType()->isVectorTy())
         {
             assert(result[1]->getType()->isVectorTy());
-#if LLVM_VERSION_MAJOR >= 11
+#if LLVM_VERSION_MAJOR >= 12
+            vecWidth = cast<FixedVectorType>(result[0]->getType())->getNumElements() +
+                       cast<FixedVectorType>(result[1]->getType())->getNumElements();
+#elif LLVM_VERSION_MAJOR >= 11
             vecWidth = cast<VectorType>(result[0]->getType())->getNumElements() +
                        cast<VectorType>(result[1]->getType())->getNumElements();
 #else



More information about the mesa-commit mailing list