llvm-exegesis broken on x86

Something’s up with the llvm-exegesis build process on 7.0.0 release. On my x86 machines they always complain “no exegesis target for x86_64-pc-linux-gnu, using default”, and this seems to be because LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET never gets set by CMake.

The CMake scripts try to set LLVM_EXEGESIS_TARGETS in the lib subdirectory, but this doesn’t seem to work properly. I made this change to figure out what’s happening:

What’s happening is that

set(LLVM_EXEGESIS_TARGETS “${LLVM_EXEGESIS_TARGETS} X86” PARENT_SCOPE)

and

set(LLVM_EXEGESIS_TARGETS “${LLVM_EXEGESIS_TARGETS} AArch64” PARENT_SCOPE)

set LLVM_EXEGESIS_TARGETS in the parent scope and not the local scope, but read from the local scope.

So when the first executes the local LLVM_EXEGESIS_TARGETS is unset so the parent LLVM_EXEGESIS_TARGETS

is set to “ X86”, but in the second the local LLVM_EXEGESIS_TARGETS is still unset so the parent

LLVM_EXEGESIS_TARGETS gets set to “ AArch64”.

As for the correct way to fix it, looking a bit at the .cmake files in llvm/cmake/modules/ it looks like the standard

way would be to have the file set LLVM_EXEGESIS_TARGETS locally, then in the parent. i.e. something like

if (LLVM_TARGETS_TO_BUILD MATCHES “X86”)

set(LLVM_EXEGESIS_TARGETS “${LLVM_EXEGESIS_TARGETS} X86”)

endif()
if (LLVM_TARGETS_TO_BUILD MATCHES “AArch64”)

set(LLVM_EXEGESIS_TARGETS “${LLVM_EXEGESIS_TARGETS} AArch64”)

endif()

set(LLVM_EXEGESIS_TARGETS “${LLVM_EXEGESIS_TARGETS}” PARENT_SCOPE)

John