Mesa (main): ac/llvm: don't create the target machine if the LLVM processor is unsupported
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Apr 25 14:05:16 UTC 2022
Module: Mesa
Branch: main
Commit: b8a6bbc6c521341daef7a839975a9d79e4ad329f
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b8a6bbc6c521341daef7a839975a9d79e4ad329f
Author: Marek Olšák <marek.olsak at amd.com>
Date: Fri Apr 22 14:05:18 2022 -0400
ac/llvm: don't create the target machine if the LLVM processor is unsupported
If a processor is unsupported, LLVM chooses "tahiti", which hangs
everything except gfx6. Check for support manually.
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16112>
---
src/amd/llvm/ac_llvm_helper.cpp | 7 +++++++
src/amd/llvm/ac_llvm_util.c | 9 ++++++++-
src/amd/llvm/ac_llvm_util.h | 1 +
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/amd/llvm/ac_llvm_helper.cpp b/src/amd/llvm/ac_llvm_helper.cpp
index 0e2e207c3a4..1fee75f30c5 100644
--- a/src/amd/llvm/ac_llvm_helper.cpp
+++ b/src/amd/llvm/ac_llvm_helper.cpp
@@ -28,6 +28,7 @@
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Target/TargetMachine.h>
+#include <llvm/MC/MCSubtargetInfo.h>
#include <llvm/Transforms/IPO.h>
#include <cstring>
@@ -43,6 +44,12 @@
#include "ac_llvm_build.h"
#include "util/macros.h"
+bool ac_is_llvm_processor_supported(LLVMTargetMachineRef tm, const char *processor)
+{
+ llvm::TargetMachine *TM = reinterpret_cast<llvm::TargetMachine *>(tm);
+ return TM->getMCSubtargetInfo()->isCPUStringValid(processor);
+}
+
void ac_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes)
{
llvm::Argument *A = llvm::unwrap<llvm::Argument>(val);
diff --git a/src/amd/llvm/ac_llvm_util.c b/src/amd/llvm/ac_llvm_util.c
index 9f215d8e0aa..d22ed0667b9 100644
--- a/src/amd/llvm/ac_llvm_util.c
+++ b/src/amd/llvm/ac_llvm_util.c
@@ -189,11 +189,18 @@ static LLVMTargetMachineRef ac_create_target_machine(enum radeon_family family,
assert(family >= CHIP_TAHITI);
const char *triple = (tm_options & AC_TM_SUPPORTS_SPILL) ? "amdgcn-mesa-mesa3d" : "amdgcn--";
LLVMTargetRef target = ac_get_llvm_target(triple);
+ const char *name = ac_get_llvm_processor_name(family);
LLVMTargetMachineRef tm =
- LLVMCreateTargetMachine(target, triple, ac_get_llvm_processor_name(family), "", level,
+ LLVMCreateTargetMachine(target, triple, name, "", level,
LLVMRelocDefault, LLVMCodeModelDefault);
+ if (!ac_is_llvm_processor_supported(tm, name)) {
+ LLVMDisposeTargetMachine(tm);
+ fprintf(stderr, "amd: LLVM doesn't support %s, bailing out...\n", name);
+ return NULL;
+ }
+
if (out_triple)
*out_triple = triple;
diff --git a/src/amd/llvm/ac_llvm_util.h b/src/amd/llvm/ac_llvm_util.h
index a568c1fc70b..3c76c716a15 100644
--- a/src/amd/llvm/ac_llvm_util.h
+++ b/src/amd/llvm/ac_llvm_util.h
@@ -90,6 +90,7 @@ struct ac_llvm_compiler {
};
const char *ac_get_llvm_processor_name(enum radeon_family family);
+bool ac_is_llvm_processor_supported(LLVMTargetMachineRef tm, const char *processor);
void ac_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes);
void ac_add_attr_alignment(LLVMValueRef val, uint64_t bytes);
bool ac_is_sgpr_param(LLVMValueRef param);
More information about the mesa-commit
mailing list