From f945cca9837815fe1fb2c7eba543ee33630fc9ca Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Thu, 1 Apr 2021 12:47:05 +0200 Subject: [PATCH] clover/llvm: handle Fixed vs Scalable vectors explicitly starting with llvm-11 This fixes compilation with llvm-13. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4200 Signed-off-by: Karol Herbst Reviewed-by: Francisco Jerez Part-of: --- src/gallium/frontends/clover/llvm/compat.hpp | 31 +++++++++++++++++++ .../frontends/clover/llvm/metadata.hpp | 6 ++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/gallium/frontends/clover/llvm/compat.hpp b/src/gallium/frontends/clover/llvm/compat.hpp index 380d16a8346..89aa0dfbf5b 100644 --- a/src/gallium/frontends/clover/llvm/compat.hpp +++ b/src/gallium/frontends/clover/llvm/compat.hpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -103,6 +104,36 @@ namespace clover { #endif d); } + + static inline bool + is_scalable_vector(const ::llvm::Type *type) + { +#if LLVM_VERSION_MAJOR >= 11 + return ::llvm::isa<::llvm::ScalableVectorType>(type); +#else + return false; +#endif + } + + static inline bool + is_fixed_vector(const ::llvm::Type *type) + { +#if LLVM_VERSION_MAJOR >= 11 + return ::llvm::isa<::llvm::FixedVectorType>(type); +#else + return type->isVectorTy(); +#endif + } + + static inline unsigned + get_fixed_vector_elements(const ::llvm::Type *type) + { +#if LLVM_VERSION_MAJOR >= 11 + return ::llvm::cast<::llvm::FixedVectorType>(type)->getNumElements(); +#else + return ((::llvm::VectorType*)type)->getNumElements(); +#endif + } } } } diff --git a/src/gallium/frontends/clover/llvm/metadata.hpp b/src/gallium/frontends/clover/llvm/metadata.hpp index e3e58a32ff9..578a50c0d21 100644 --- a/src/gallium/frontends/clover/llvm/metadata.hpp +++ b/src/gallium/frontends/clover/llvm/metadata.hpp @@ -128,8 +128,10 @@ namespace clover { data += "long"; break; } - if (type->isVectorTy()) - data += std::to_string(((::llvm::VectorType*)type)->getNumElements()); + if (compat::is_scalable_vector(type)) + throw build_error("hit unexpected scalable vector"); + if (compat::is_fixed_vector(type)) + data += std::to_string(compat::get_fixed_vector_elements(type)); } else { ::llvm::raw_string_ostream os { data };