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
From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Steven
Noonan via llvm-dev
Sent: 20 September 2018 16:42
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] 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:
---
diff --git a/tools/llvm-exegesis/CMakeLists.txt
b/tools/llvm-exegesis/CMakeLists.txt
index 65b1ada8529..94842519ca7 100644
--- a/tools/llvm-exegesis/CMakeLists.txt
+++ b/tools/llvm-exegesis/CMakeLists.txt
@@ -8,7 +8,9 @@ add_llvm_tool(llvm-exegesis
llvm-exegesis.cpp
)
+message(WARNING "LLVM_EXEGESIS_TARGETS at parent scope before:
${LLVM_EXEGESIS_TARGETS}")
add_subdirectory(lib)
+message(FATAL_ERROR "LLVM_EXEGESIS_TARGETS at parent scope after:
${LLVM_EXEGESIS_TARGETS}")
# Link the native exegesis target if compiled and on the right host.
if ((LLVM_TARGETS_TO_BUILD MATCHES "${LLVM_NATIVE_ARCH}") AND
(LLVM_EXEGESIS_TARGETS MATCHES "${LLVM_NATIVE_ARCH}"))
diff --git a/tools/llvm-exegesis/lib/CMakeLists.txt
b/tools/llvm-exegesis/lib/CMakeLists.txt
index 175c2adf9de..4dc91ef125c 100644
--- a/tools/llvm-exegesis/lib/CMakeLists.txt
+++ b/tools/llvm-exegesis/lib/CMakeLists.txt
@@ -1,12 +1,18 @@
+message( WARNING "LLVM_EXEGESIS_TARGETS before:
${LLVM_EXEGESIS_TARGETS}" )
+
if (LLVM_TARGETS_TO_BUILD MATCHES "X86")
add_subdirectory(X86)
+ message( WARNING "Appending X86" )
set(LLVM_EXEGESIS_TARGETS "${LLVM_EXEGESIS_TARGETS} X86"
PARENT_SCOPE)
endif()
if (LLVM_TARGETS_TO_BUILD MATCHES "AArch64")
add_subdirectory(AArch64)
+ message( WARNING "Appending AArch64" )
set(LLVM_EXEGESIS_TARGETS "${LLVM_EXEGESIS_TARGETS} AArch64"
PARENT_SCOPE)
endif()
+message( WARNING "LLVM_EXEGESIS_TARGETS after:
${LLVM_EXEGESIS_TARGETS}" )
+
add_library(LLVMExegesis
STATIC
Analysis.cpp
---
This results in this behavior (extraneous newlines removed for readability):
CMake Warning at tools/llvm-exegesis/CMakeLists.txt:11 (message):
LLVM_EXEGESIS_TARGETS at parent scope before:
CMake Warning at tools/llvm-exegesis/lib/CMakeLists.txt:1 (message):
LLVM_EXEGESIS_TARGETS before:
CMake Warning at tools/llvm-exegesis/lib/CMakeLists.txt:5 (message):
Appending X86
CMake Warning at tools/llvm-exegesis/lib/CMakeLists.txt:10 (message):
Appending AArch64
CMake Warning at tools/llvm-exegesis/lib/CMakeLists.txt:14 (message):
LLVM_EXEGESIS_TARGETS after:
CMake Error at tools/llvm-exegesis/CMakeLists.txt:13 (message):
LLVM_EXEGESIS_TARGETS at parent scope after: AArch64
So reading the LLVM_EXEGESIS_TARGETS variable in lib/CMakeLists.txt doesn't
work properly, and the second set(... PARENT_SCOPE) just sees the empty
LLVM_EXEGESIS_TARGETS value, overwriting the previously appended X86 value.
Any ideas on how to fix this? I'm doing this locally but it seems sloppy:
diff --git a/tools/llvm-exegesis/lib/CMakeLists.txt
b/tools/llvm-exegesis/lib/CMakeLists.txt
index 175c2adf9de..194304adf98 100644
--- a/tools/llvm-exegesis/lib/CMakeLists.txt
+++ b/tools/llvm-exegesis/lib/CMakeLists.txt
@@ -1,12 +1,16 @@
+set(TARGETS_TO_APPEND "")
+
if (LLVM_TARGETS_TO_BUILD MATCHES "X86")
add_subdirectory(X86)
- set(LLVM_EXEGESIS_TARGETS "${LLVM_EXEGESIS_TARGETS} X86"
PARENT_SCOPE)
+ set(TARGETS_TO_APPEND "${TARGETS_TO_APPEND} X86")
endif()
if (LLVM_TARGETS_TO_BUILD MATCHES "AArch64")
add_subdirectory(AArch64)
- set(LLVM_EXEGESIS_TARGETS "${LLVM_EXEGESIS_TARGETS} AArch64"
PARENT_SCOPE)
+ set(TARGETS_TO_APPEND "${TARGETS_TO_APPEND} AArch64")
endif()
+set(LLVM_EXEGESIS_TARGETS "${LLVM_EXEGESIS_TARGETS}
${TARGETS_TO_APPEND}" PARENT_SCOPE)
+
add_library(LLVMExegesis
STATIC
Analysis.cpp
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20180920/4992ac83/attachment.html>