Skip to content

[compiler-rt][X86] Use functions in cpuid.h instead of inline assembly #97877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

boomanaiden154
Copy link
Contributor

This patch makes the host/feature detection in compiler-rt and LLVM use the functions provided in cpuid.h(__get_cpuid, __get_cpuid_count) instead of inline assembly. This simplifies the implementation and moves any inline assembly away to a more common place.

A while ago, some similar cleanup was attempted, but this ended up resulting in some compilation errors due to toolchain minimum version issues (https://bugs.llvm.org/show_bug.cgi?id=30384). After the reversion landed, there have been no attempts since then to clean up the code, even though the minimum supported compilers now support the relevant functions (https://godbolt.org/z/o1Mjz8ndv).

This patch makes the host/feature detection in compiler-rt and LLVM use
the functions provided in cpuid.h(__get_cpuid, __get_cpuid_count)
instead of inline assembly. This simplifies the implementation and moves
any inline assembly away to a more common place.

A while ago, some similar cleanup was attempted, but this ended up
resulting in some compilation errors due to toolchain minimum version
issues (https://bugs.llvm.org/show_bug.cgi?id=30384). After the
reversion landed, there have been no attempts since then to clean up the
code, even though the minimum supported compilers now support the
relevant functions (https://godbolt.org/z/o1Mjz8ndv).
Copy link

github-actions bot commented Jul 6, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@MaskRay
Copy link
Member

MaskRay commented Jul 6, 2024

clang/lib/Headers/cpuid.h did not define __get_cpuid_count before f6e8408 (2017). Clang 5.0.0 (Sep 2017 https://www.llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library) contains the commit. Nice:)

@boomanaiden154
Copy link
Contributor Author

clang/lib/Headers/cpuid.h did not define __get_cpuid_count before f6e8408 (2017). Clang 5.0.0 (Sep 2017 https://www.llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library) contains the commit. Nice:)

Yep. I was a bit surprised when I saw everything was included in the minimum supported compiler versions as well. It definitely makes the code a lot cleaner and hopefully more robust as now there's one less inline assembly implementation.

@boomanaiden154 boomanaiden154 merged commit 19cf8de into llvm:main Jul 8, 2024
7 checks passed
@boomanaiden154 boomanaiden154 deleted the x86-get-cpu-info-cpuid-header branch July 8, 2024 17:54
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 8, 2024

LLVM Buildbot has detected a new failure on builder libc-aarch64-ubuntu-fullbuild-dbg running on libc-aarch64-ubuntu while building compiler-rt,llvm at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/71/builds/1636

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
PASS __vn_powf in [0x1.ep-1;0x1.1p+0] x [-0x1p+8;-0x1p+14] round n errlim 2.1 maxerr 1.69687 +0.5 cnt 50000 cnt1 2382 4.764% cnt2 20 0.04% cntfail 0 0%
PASS _ZGVnN4vv_powf in [0x1p-1;0x1p+1] x [0x1p-7;0x1p+7] round n errlim 2.1 maxerr 0.0155004 +0.5 cnt 50000 cnt1 60 0.12% cnt2 0 0% cntfail 0 0%
PASS _ZGVnN4vv_powf in [0x1p-1;0x1p+1] x [-0x1p-7;-0x1p+7] round n errlim 2.1 maxerr 0.0212817 +0.5 cnt 50000 cnt1 57 0.114% cnt2 0 0% cntfail 0 0%
PASS _ZGVnN4vv_powf in [0x1p-70;0x1p+70] x [0x1p-1;0x1p+1] round n errlim 2.1 maxerr 0.00117655 +0.5 cnt 50000 cnt1 32 0.064% cnt2 0 0% cntfail 0 0%
PASS _ZGVnN4vv_powf in [0x1p-70;0x1p+70] x [-0x1p-1;-0x1p+1] round n errlim 2.1 maxerr 0.00122117 +0.5 cnt 50000 cnt1 33 0.066% cnt2 0 0% cntfail 0 0%
PASS _ZGVnN4vv_powf in [0x1.ep-1;0x1.1p+0] x [0x1p+8;0x1p+14] round n errlim 2.1 maxerr 1.74019 +0.5 cnt 50000 cnt1 2429 4.858% cnt2 31 0.062% cntfail 0 0%
PASS _ZGVnN4vv_powf in [0x1.ep-1;0x1.1p+0] x [-0x1p+8;-0x1p+14] round n errlim 2.1 maxerr 1.69687 +0.5 cnt 50000 cnt1 2382 4.764% cnt2 20 0.04% cntfail 0 0%
@@@BUILD_STEP Benchmark Utils Tests@@@
Running: ninja libc-benchmark-util-tests
[1/5] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o
FAILED: lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o 
/usr/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/TargetParser -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/llvm/lib/TargetParser -Iinclude -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/llvm/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g  -fno-exceptions -funwind-tables -fno-rtti -std=c++17 -MD -MT lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o -MF lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o.d -o lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/llvm/lib/TargetParser/Host.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/llvm/lib/TargetParser/Host.cpp:54:
/usr/lib/llvm-11/lib/clang/11.0.1/include/cpuid.h:11:2: error: this header is for x86 only
#error this header is for x86 only
 ^
/usr/lib/llvm-11/lib/clang/11.0.1/include/cpuid.h:280:5: error: invalid output constraint '=a' in asm
    __cpuid(__leaf, __eax, __ebx, __ecx, __edx);
    ^
/usr/lib/llvm-11/lib/clang/11.0.1/include/cpuid.h:245:11: note: expanded from macro '__cpuid'
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
          ^
/usr/lib/llvm-11/lib/clang/11.0.1/include/cpuid.h:295:5: error: invalid output constraint '=a' in asm
    __cpuid(__leaf, *__eax, *__ebx, *__ecx, *__edx);
    ^
/usr/lib/llvm-11/lib/clang/11.0.1/include/cpuid.h:245:11: note: expanded from macro '__cpuid'
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
          ^
/usr/lib/llvm-11/lib/clang/11.0.1/include/cpuid.h:309:5: error: invalid output constraint '=a' in asm
    __cpuid_count(__leaf, __subleaf, *__eax, *__ebx, *__ecx, *__edx);
    ^
/usr/lib/llvm-11/lib/clang/11.0.1/include/cpuid.h:252:11: note: expanded from macro '__cpuid_count'
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
          ^
4 errors generated.
ninja: build stopped: subcommand failed.
['ninja', 'libc-benchmark-util-tests'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 164, in step
    yield
  File "../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 151, in main
    run_command(['ninja', 'libc-benchmark-util-tests'])
  File "../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 179, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-zorg/zorg/buildbot/builders/annotated/util.py", line 49, in report_run_cmd
    subprocess.check_call(cmd, shell=shell, *args, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 190, in check_call
    raise CalledProcessError(retcode, cmd)

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 8, 2024

LLVM Buildbot has detected a new failure on builder lldb-x86_64-debian running on lldb-x86_64-debian while building compiler-rt,llvm at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/162/builds/1578

Here is the relevant piece of the build log for the reference:

Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: commands/expression/static-initializers/TestStaticInitializers.py (217 of 2628)
PASS: lldb-api :: commands/target/stop-hooks/TestStopHookScripted.py (218 of 2628)
PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentDelaySignalBreak.py (219 of 2628)
PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentDelayedCrashWithBreakpointSignal.py (220 of 2628)
PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentDelayWatchBreak.py (221 of 2628)
PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentDelaySignalWatch.py (222 of 2628)
PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentSignalDelayWatch.py (223 of 2628)
PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentBreakpointDelayBreakpointOneSignal.py (224 of 2628)
PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentWatchBreakDelay.py (225 of 2628)
UNRESOLVED: lldb-api :: python_api/global_module_cache/TestGlobalModuleCache.py (226 of 2628)
******************** TEST 'lldb-api :: python_api/global_module_cache/TestGlobalModuleCache.py' FAILED ********************
Script:
--
/usr/bin/python3 /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env ARCHIVER=/usr/bin/ar --env OBJCOPY=/usr/bin/objcopy --env LLVM_LIBS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./lib --env LLVM_INCLUDE_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/include --env LLVM_TOOLS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./bin --arch x86_64 --build-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex --lldb-module-cache-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/lldb --compiler /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/clang --dsymutil /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/dsymutil --llvm-tools-dir /home/worker/2.0.1/lldb-x86_64-debian/build/./bin --lldb-obj-root /home/worker/2.0.1/lldb-x86_64-debian/build/tools/lldb --lldb-libs-dir /home/worker/2.0.1/lldb-x86_64-debian/build/./lib -t /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/python_api/global_module_cache -p TestGlobalModuleCache.py
--
Exit Code: -6

Command Output (stdout):
--
lldb version 19.0.0git (https://github.com/llvm/llvm-project.git revision 19cf8deabe1124831164987f1b9bf2f806c0a875)
  clang revision 19cf8deabe1124831164987f1b9bf2f806c0a875
  llvm revision 19cf8deabe1124831164987f1b9bf2f806c0a875

--
Command Output (stderr):
--
Change dir to: /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/python_api/global_module_cache
UNSUPPORTED: LLDB (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/clang-x86_64) :: test_OneTargetOneDebugger_dsym (TestGlobalModuleCache.GlobalModuleCacheTestCase.test_OneTargetOneDebugger_dsym) (test case does not fall in any category of interest for this run) 
runCmd: settings clear -all

output: 

runCmd: settings set symbols.enable-external-lookup false

output: 

runCmd: settings set target.inherit-tcc true

output: 

runCmd: settings set target.disable-aslr false

output: 

runCmd: settings set target.detach-on-error false

output: 

runCmd: settings set target.auto-apply-fixits false

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 8, 2024

LLVM Buildbot has detected a new failure on builder ppc64le-mlir-rhel-clang running on ppc64le-mlir-rhel-test while building compiler-rt,llvm at step 5 "build-check-mlir-build-only".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/1509

Here is the relevant piece of the build log for the reference:

Step 5 (build-check-mlir-build-only) failure: build (failure)
...
8.089 [1350/13/2610] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/Target.cpp.o
8.090 [1350/12/2611] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/TextAPIError.cpp.o
8.090 [1350/11/2612] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/TextStub.cpp.o
8.090 [1350/10/2613] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/TextStubCommon.cpp.o
8.090 [1350/9/2614] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/Utils.cpp.o
8.091 [1350/8/2615] Building CXX object lib/WindowsDriver/CMakeFiles/LLVMWindowsDriver.dir/MSVCPaths.cpp.o
8.091 [1350/7/2616] Building CXX object tools/mlir/tools/mlir-linalg-ods-gen/CMakeFiles/mlir-linalg-ods-yaml-gen.dir/mlir-linalg-ods-yaml-gen.cpp.o
8.091 [1350/6/2617] Building CXX object tools/llc/CMakeFiles/llc.dir/llc.cpp.o
8.092 [1350/5/2618] Building CXX object tools/llc/CMakeFiles/llc.dir/NewPMDriver.cpp.o
8.834 [1350/4/2619] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o
FAILED: lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o 
ccache /home/buildbots/llvm-external-buildbots/clang.16.0.1/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-mlir-rhel-test/ppc64le-mlir-rhel-clang-build/build/lib/TargetParser -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-mlir-rhel-test/ppc64le-mlir-rhel-clang-build/llvm-project/llvm/lib/TargetParser -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-mlir-rhel-test/ppc64le-mlir-rhel-clang-build/build/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-mlir-rhel-test/ppc64le-mlir-rhel-clang-build/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o -MF lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o.d -o lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o -c /home/buildbots/llvm-external-buildbots/workers/ppc64le-mlir-rhel-test/ppc64le-mlir-rhel-clang-build/llvm-project/llvm/lib/TargetParser/Host.cpp
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-mlir-rhel-test/ppc64le-mlir-rhel-clang-build/llvm-project/llvm/lib/TargetParser/Host.cpp:54:
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:14:2: error: this header is for x86 only
#error this header is for x86 only
 ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:298:5: error: invalid output constraint '=a' in asm
    __cpuid(__leaf, __eax, __ebx, __ecx, __edx);
    ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:262:11: note: expanded from macro '__cpuid'
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
          ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:313:5: error: invalid output constraint '=a' in asm
    __cpuid(__leaf, *__eax, *__ebx, *__ecx, *__edx);
    ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:262:11: note: expanded from macro '__cpuid'
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
          ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:327:5: error: invalid output constraint '=a' in asm
    __cpuid_count(__leaf, __subleaf, *__eax, *__ebx, *__ecx, *__edx);
    ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:269:11: note: expanded from macro '__cpuid_count'
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
          ^
4 errors generated.
11.285 [1350/3/2620] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/IRSymtab.cpp.o
16.071 [1350/2/2621] Building CXX object lib/MC/MCParser/CMakeFiles/LLVMMCParser.dir/AsmParser.cpp.o
22.073 [1350/1/2622] Building CXX object lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/AsmPrinter.cpp.o
ninja: build stopped: subcommand failed.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 8, 2024

LLVM Buildbot has detected a new failure on builder flang-aarch64-libcxx running on linaro-flang-aarch64-libcxx while building compiler-rt,llvm at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/89/builds/1597

Here is the relevant piece of the build log for the reference:

Step 5 (build-unified-tree) failure: build (failure)
...
46.378 [4073/33/2989] Copying clang's amxfp16intrin.h...
46.379 [4073/32/2990] Copying clang's amxintrin.h...
46.379 [4073/31/2991] Copying clang's avx2intrin.h...
46.379 [4073/30/2992] Copying clang's avx512bf16intrin.h...
46.380 [4073/29/2993] Copying clang's avx512bitalgintrin.h...
46.380 [4073/28/2994] Copying clang's avx512bwintrin.h...
46.380 [4073/27/2995] Copying clang's avx512cdintrin.h...
46.381 [4073/26/2996] Copying clang's avx512dqintrin.h...
46.384 [4073/25/2997] Building CXX object tools/llvm-lto2/CMakeFiles/llvm-lto2.dir/llvm-lto2.cpp.o
46.401 [4073/24/2998] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o
FAILED: lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o 
/usr/local/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/lib/TargetParser -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/lib/TargetParser -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/include -stdlib=libc++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror=global-constructors -O3 -DNDEBUG -fPIC  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o -MF lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o.d -o lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/lib/TargetParser/Host.cpp
In file included from /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/lib/TargetParser/Host.cpp:54:
/usr/local/clang+llvm-17.0.6-aarch64-linux-gnu/lib/clang/17/include/cpuid.h:14:2: error: this header is for x86 only
   14 | #error this header is for x86 only
      |  ^
/usr/local/clang+llvm-17.0.6-aarch64-linux-gnu/lib/clang/17/include/cpuid.h:298:5: error: invalid output constraint '=a' in asm
  298 |     __cpuid(__leaf, __eax, __ebx, __ecx, __edx);
      |     ^
/usr/local/clang+llvm-17.0.6-aarch64-linux-gnu/lib/clang/17/include/cpuid.h:262:11: note: expanded from macro '__cpuid'
  262 |         : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
      |           ^
/usr/local/clang+llvm-17.0.6-aarch64-linux-gnu/lib/clang/17/include/cpuid.h:313:5: error: invalid output constraint '=a' in asm
  313 |     __cpuid(__leaf, *__eax, *__ebx, *__ecx, *__edx);
      |     ^
/usr/local/clang+llvm-17.0.6-aarch64-linux-gnu/lib/clang/17/include/cpuid.h:262:11: note: expanded from macro '__cpuid'
  262 |         : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
      |           ^
/usr/local/clang+llvm-17.0.6-aarch64-linux-gnu/lib/clang/17/include/cpuid.h:327:5: error: invalid output constraint '=a' in asm
  327 |     __cpuid_count(__leaf, __subleaf, *__eax, *__ebx, *__ecx, *__edx);
      |     ^
/usr/local/clang+llvm-17.0.6-aarch64-linux-gnu/lib/clang/17/include/cpuid.h:269:11: note: expanded from macro '__cpuid_count'
  269 |         : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
      |           ^
4 errors generated.
46.491 [4073/23/2999] Building CXX object tools/mlir/tools/tblgen-lsp-server/CMakeFiles/tblgen-lsp-server.dir/tblgen-lsp-server.cpp.o
46.585 [4073/22/3000] Building CXX object tools/mlir/tools/mlir-src-sharder/CMakeFiles/mlir-src-sharder.dir/mlir-src-sharder.cpp.o
46.587 [4073/21/3001] Building CXX object tools/mlir/lib/Tools/PDLL/AST/CMakeFiles/obj.MLIRPDLLAST.dir/Context.cpp.o
46.590 [4073/20/3002] Building CXX object tools/mlir/lib/Tools/PDLL/AST/CMakeFiles/obj.MLIRPDLLAST.dir/Diagnostic.cpp.o
46.593 [4073/19/3003] Building CXX object tools/mlir/lib/Analysis/Presburger/CMakeFiles/obj.MLIRPresburger.dir/PresburgerRelation.cpp.o
46.595 [4073/18/3004] Building CXX object tools/mlir/lib/Tools/PDLL/AST/CMakeFiles/obj.MLIRPDLLAST.dir/NodePrinter.cpp.o
46.597 [4073/17/3005] Building CXX object tools/mlir/lib/CAPI/Debug/CMakeFiles/obj.MLIRCAPIDebug.dir/Debug.cpp.o
46.599 [4073/16/3006] Building CXX object tools/mlir/lib/Analysis/Presburger/CMakeFiles/obj.MLIRPresburger.dir/PresburgerSpace.cpp.o
46.600 [4073/15/3007] Building CXX object tools/mlir/lib/Tools/PDLL/AST/CMakeFiles/obj.MLIRPDLLAST.dir/Nodes.cpp.o
46.602 [4073/14/3008] Building CXX object tools/mlir/lib/Tools/PDLL/AST/CMakeFiles/obj.MLIRPDLLAST.dir/Types.cpp.o
46.604 [4073/13/3009] Building CXX object tools/mlir/lib/Analysis/Presburger/CMakeFiles/obj.MLIRPresburger.dir/PWMAFunction.cpp.o
46.605 [4073/12/3010] Building CXX object tools/mlir/lib/Analysis/Presburger/CMakeFiles/obj.MLIRPresburger.dir/Utils.cpp.o
46.607 [4073/11/3011] Building CXX object tools/mlir/lib/Analysis/Presburger/CMakeFiles/obj.MLIRPresburger.dir/Simplex.cpp.o
46.608 [4073/10/3012] Building CXX object tools/mlir/lib/Analysis/Presburger/CMakeFiles/obj.MLIRPresburger.dir/IntegerRelation.cpp.o

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 8, 2024

LLVM Buildbot has detected a new failure on builder ppc64le-flang-rhel-clang running on ppc64le-flang-rhel-test while building compiler-rt,llvm at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/1991

Here is the relevant piece of the build log for the reference:

Step 5 (build-unified-tree) failure: build (failure)
...
9.902 [1679/14/4784] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/Indexing.cpp.o
9.966 [1679/13/4785] Building CXX object tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/HIPUtility.cpp.o
9.968 [1679/12/4786] Building CXX object tools/clang/tools/driver/CMakeFiles/clang.dir/cc1_main.cpp.o
9.968 [1679/11/4787] Building CXX object tools/clang/tools/clang-scan-deps/CMakeFiles/clang-scan-deps.dir/ClangScanDeps.cpp.o
9.969 [1679/10/4788] Building CXX object tools/clang/tools/clang-check/CMakeFiles/clang-check.dir/ClangCheck.cpp.o
10.038 [1679/9/4789] Building CXX object tools/clang/tools/clang-repl/CMakeFiles/clang-repl.dir/ClangRepl.cpp.o
10.067 [1679/8/4790] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXExtractAPI.cpp.o
10.084 [1679/7/4791] Building CXX object tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/core_main.cpp.o
10.234 [1679/6/4792] Building CXX object tools/clang/tools/clang-installapi/CMakeFiles/clang-installapi.dir/ClangInstallAPI.cpp.o
10.235 [1679/5/4793] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o
FAILED: lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o 
ccache /home/buildbots/llvm-external-buildbots/clang.16.0.1/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/lib/TargetParser -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/lib/TargetParser -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o -MF lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o.d -o lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o -c /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/lib/TargetParser/Host.cpp
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/lib/TargetParser/Host.cpp:54:
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:14:2: error: this header is for x86 only
#error this header is for x86 only
 ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:298:5: error: invalid output constraint '=a' in asm
    __cpuid(__leaf, __eax, __ebx, __ecx, __edx);
    ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:262:11: note: expanded from macro '__cpuid'
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
          ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:313:5: error: invalid output constraint '=a' in asm
    __cpuid(__leaf, *__eax, *__ebx, *__ecx, *__edx);
    ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:262:11: note: expanded from macro '__cpuid'
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
          ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:327:5: error: invalid output constraint '=a' in asm
    __cpuid_count(__leaf, __subleaf, *__eax, *__ebx, *__ecx, *__edx);
    ^
/home/buildbots/llvm-external-buildbots/clang.16.0.1/lib/clang/16/include/cpuid.h:269:11: note: expanded from macro '__cpuid_count'
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
          ^
4 errors generated.
12.328 [1679/4/4794] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/IRSymtab.cpp.o
16.714 [1679/3/4795] Building CXX object lib/MC/MCParser/CMakeFiles/LLVMMCParser.dir/AsmParser.cpp.o
22.641 [1679/2/4796] Building CXX object lib/LTO/CMakeFiles/LLVMLTO.dir/LTO.cpp.o
22.920 [1679/1/4797] Building CXX object lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/AsmPrinter.cpp.o
ninja: build stopped: subcommand failed.

boomanaiden154 added a commit that referenced this pull request Jul 8, 2024
… assembly (#97877)"

This reverts commit 19cf8de.

This was causing quite a few buildbot failures (see the PR description).
Reverting for now while I have time to sort it out. Seems like it should
just be conditional preprocessor macros for X86 however.
boomanaiden154 added a commit that referenced this pull request Jul 8, 2024
…f inline assembly (#97877)""

This reverts commit 2039e13.

This relands commit 19cf8de.

Added some additional preprocessor directives to ensure that Host.cpp
only includes cpuid.h when being built on x86.
boomanaiden154 added a commit that referenced this pull request Jul 9, 2024
… assembly (#97877)"

This reverts commit f6616e9.

Was causing buildbot failures on Windows. I also remember seeing a
AMDGPU buildbot failing somewhere on a warning as they have -Werror
enabled.
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
… assembly (llvm#97877)"

This reverts commit f6616e9.

Was causing buildbot failures on Windows. I also remember seeing a
AMDGPU buildbot failing somewhere on a warning as they have -Werror
enabled.
boomanaiden154 added a commit that referenced this pull request Jul 24, 2024
… assembly (#97877)"

This reverts commit f1905f0.

This relands commit 19cf8de.

There were issues with the preprocessor includes that should have
excluded MSVC still including clang functions building on windows and
using intrin.h. This relanding fixes this behavior by additionally
wrapping the uses of __get_cpuid and __get_cpuid_count in _MSC_VER so
that clang in MSVC mode, which includes intrin.h, does not have any
conflicts.
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
… assembly (#97877)"

Summary:
This reverts commit f1905f0.

This relands commit 19cf8de.

There were issues with the preprocessor includes that should have
excluded MSVC still including clang functions building on windows and
using intrin.h. This relanding fixes this behavior by additionally
wrapping the uses of __get_cpuid and __get_cpuid_count in _MSC_VER so
that clang in MSVC mode, which includes intrin.h, does not have any
conflicts.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250754
@kraj
Copy link
Contributor

kraj commented Aug 27, 2024

@boomanaiden154 this is causing a build regression when compiling standalone compiler-rt for x86_64 in a cross build environment

/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/compiler-rt/20.0.0/recipe-sysroot-native/usr/bin/x86_64-yoe-linux-musl/x86_64-yoe-linux-musl-clang --target=x86_64-yoe-linux-musl --sysroot=/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/compiler-rt/20.0.0/recipe-sysroot -DVISIBILITY_HIDDEN -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/compiler-rt/20.0.0/compiler-rt-20.0.0/projects/compiler-rt/lib/builtins -I/mnt/b/yoe/master/workspace/sources/llvm-project/compiler-rt/lib/builtins -I/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/compiler-rt/20.0.0/compiler-rt-20.0.0/include -I/mnt/b/yoe/master/workspace/sources/llvm-project/llvm/include -target x86_64-yoe-linux-musl  -m64 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -mlittle-endian --dyld-prefix=/usr -Qunused-arguments -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  --sysroot=/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/compiler-rt/20.0.0/recipe-sysroot  -O2 -g   -fmacro-prefix-map=/mnt/b/yoe/master/workspace/sources/llvm-project=/usr/src/debug/compiler-rt/20.0.0  -fdebug-prefix-map=/mnt/b/yoe/master/workspace/sources/llvm-project=/usr/src/debug/compiler-rt/20.0.0  -fmacro-prefix-map=/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/compiler-rt/20.0.0/compiler-rt-20.0.0=/usr/src/debug/compiler-rt/20.0.0  -fdebug-prefix-map=/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/compiler-rt/20.0.0/compiler-rt-20.0.0=/usr/src/debug/compiler-rt/20.0.0  -fdebug-prefix-map=/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/compiler-rt/20.0.0/recipe-sysroot=  -fmacro-prefix-map=/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/compiler-rt/20.0.0/recipe-sysroot=  -fdebug-prefix-map=/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/compiler-rt/20.0.0/recipe-sysroot-native=  -pipe -fPIC -fno-semantic-interposition -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -O2 -g -DNDEBUG -fPIC -fno-lto -Werror=array-bounds -Werror=uninitialized -Werror=shadow -Werror=empty-body -Werror=sizeof-pointer-memaccess -Werror=sizeof-array-argument -Werror=suspicious-memaccess -Werror=builtin-memcpy-chk-size -Werror=array-bounds-pointer-arithmetic -Werror=return-stack-address -Werror=sizeof-array-decay -Werror=format-insufficient-args -Wformat -std=c11 -DCOMPILER_RT_HAS_FLOAT16 -MD -MT projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/cpu_model/x86.c.o -MF projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/cpu_model/x86.c.o.d -o projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/cpu_model/x86.c.o -c /mnt/b/yoe/master/workspace/sources/llvm-project/compiler-rt/lib/builtins/cpu_model/x86.c

/mnt/b/yoe/master/workspace/sources/llvm-project/compiler-rt/lib/builtins/cpu_model/x86.c:27:10: fatal error: 'cpuid.h' file not found
   27 | #include <cpuid.h>
      |          ^~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.

if I manually add -I/mnt/b/yoe/master/workspace/sources/llvm-project/clang/lib/Headers/ to compiler invocation then it works but I thought it should be automatically added ?

@boomanaiden154
Copy link
Contributor Author

You're going to have to provide more details about your environment.

The compiler invocation should theoretically pickup the builtin headers. I'm not sure why it isn't in your environment. That (to me) seems like an issue with your environment rather than an issue with the patch though.

@kraj
Copy link
Contributor

kraj commented Aug 27, 2024

You're going to have to provide more details about your environment.

The compiler invocation should theoretically pickup the builtin headers. I'm not sure why it isn't in your environment. That (to me) seems like an issue with your environment rather than an issue with the patch though.

its possible, let me do a bit more diving, if I revert this patch then it starts to build which is perhaps that it does not need to include the header so it works.

@kraj
Copy link
Contributor

kraj commented Aug 27, 2024

You're going to have to provide more details about your environment.
The compiler invocation should theoretically pickup the builtin headers. I'm not sure why it isn't in your environment. That (to me) seems like an issue with your environment rather than an issue with the patch though.

its possible, let me do a bit more diving, if I revert this patch then it starts to build which is perhaps that it does not need to include the header so it works.

yeah pilot error ! a rebase of local patch went wrong. sorry for noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants