hip@4.5.2: fix installation (#31416)

In a fast-moving project with as many forks as LLVM, it's difficult to
accurately determine if a function exists just by checking the version
number. The existing version check fails, for example, with llvm-amdgpu
from ROCm 4.5. It is more robust to directly check if the function
exists.
This commit is contained in:
Cory Bloor 2022-08-22 04:39:09 -06:00 committed by GitHub
parent 4c64a0fab2
commit dde6d00ab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 24 deletions

View File

@ -0,0 +1,32 @@
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index be288ab02e2..378381b16ff 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -616,11 +616,23 @@
return LLVMGetValueKind(v) == LLVMFunctionValueKind;
}
+// setOverrideStackAlignment if it exists, but SFINAE
+template <typename T>
+static auto try_set_override_stack_alignment(T* M, unsigned align)
+ -> decltype(M->setOverrideStackAlignment(align))
+{
+ M->setOverrideStackAlignment(align);
+}
+
+template <typename T>
+static void try_set_override_stack_alignment(T M, unsigned align)
+{
+// fallback for when setOverrideStackAlignment does not exist
+}
+
extern "C" void
lp_set_module_stack_alignment_override(LLVMModuleRef MRef, unsigned align)
{
-#if LLVM_VERSION_MAJOR >= 13
llvm::Module *M = llvm::unwrap(MRef);
- M->setOverrideStackAlignment(align);
-#endif
+ try_set_override_stack_alignment(M, align);
}

View File

@ -1,23 +0,0 @@
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index be288ab02e2..378381b16ff 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -619,8 +619,15 @@ lp_is_function(LLVMValueRef v)
extern "C" void
lp_set_module_stack_alignment_override(LLVMModuleRef MRef, unsigned align)
{
-#if LLVM_VERSION_MAJOR >= 13
- llvm::Module *M = llvm::unwrap(MRef);
- M->setOverrideStackAlignment(align);
+// Check that the LLVM version is >= 13.0.0 "release"
+// llvm::Module::setOverrideStackAlignment was added during the LLVM 13.0.0 development cycle and
+// cannot be guarenteed to exist until the official release.
+#if ( \
+ LLVM_VERSION_MAJOR > 13 || \
+ (LLVM_VERSION_MAJOR == 13 && \
+ (LLVM_VERSION_MINOR > 0 || \
+ (LLVM_VERSION_MINOR == 0 && (LLVM_VERSION_PATCH > 0 || !defined(LLVM_VERSION_SUFFIX))))))
+ llvm::Module* M = llvm::unwrap(MRef);
+ M->setOverrideStackAlignment(align);
#endif
}

View File

@ -143,7 +143,10 @@ class Mesa(MesonPackage):
when="@21.0.0:21.0.3", when="@21.0.0:21.0.3",
) )
patch("mesa_check_llvm_version_suffix.patch", when="@21.2.3:") # llvm::Module::setOverrideStackAlignment was added in LLVM 13.0.0, but forks based
# on development versions of LLVM 13 may or may not have it. Use SFINAE to detect
# the existence of the function and call it only if it is available.
patch("handle_missing_set_override_stack_alignment.patch", when="@21.2.3:")
# Explicitly use the llvm-config tool # Explicitly use the llvm-config tool
def patch(self): def patch(self):