From b8a6bbc6c521341daef7a839975a9d79e4ad329f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 22 Apr 2022 14:05:18 -0400 Subject: [PATCH] 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 Part-of: --- 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 #include #include +#include #include #include @@ -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(tm); + return TM->getMCSubtargetInfo()->isCPUStringValid(processor); +} + void ac_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes) { llvm::Argument *A = llvm::unwrap(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);